Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Ronald Roe

Thread: X, Y Centering

  1. #1
    Member Cranavvo's Avatar
    Join Date
    Sep 2013
    Location
    St. Helens, England
    Posts
    70
    Member #
    37189
    Liked
    11 times

    X, Y Centering

    Hey there guys, thought I'd just throw this in discussion as it's a very fuelled debate in the world of HTML & CSS, alike.

    What is your way of X, Y Centering of content upon a webpage. I've never been able to absolutely center something on a Y-position but only X by wrappers.

    I know there's use of tables, but then again, CSS lessons teach us that tables are inadequate use of content alignment, so where's the logic in using tables?

    What do you think?

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    There are several ways to center horizontally, but only 2 I know of for vertically:
    1. Set the top offset to 50%, and the top margin to negative half the height of the container.
    Code:
    element{
    position:relative;
    height:400px;
    top:50%;
    margin-top:-200px;
    }
    2. Use absolute (or fixed) positioning with auto margin.
    Code:
    element{
    position:absolute;
    height:##;
    width:##;
    top:0;right:0;bottom:0;left:0; 
    margin: auto;
    }
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    I don't do this at all, for two reasons

    1) Whenever something is centered on the page, there will come a situation where the content of the box will not fit inside of the boundaries, necessitating either scrollbars, or the redesigning of content into a JPG or something that would make it look pretty silly.
    2) There are cases where the box doesn't fit on the screen, in which case the edges get chopped off.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    It should be used sparingly, no doubt. Doing option 2 with fixed positioning makes an easy CSS modal window.
    TheGAME1264 likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  6. #5
    Member Cranavvo's Avatar
    Join Date
    Sep 2013
    Location
    St. Helens, England
    Posts
    70
    Member #
    37189
    Liked
    11 times
    I don't understand why in CS3 there was no method of absolute x and/or y centering of content on a page, that would help a lot of people.

    Edit: (without wrappers and auto margins)

  7. #6
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    Probably because it doesn't fit in all screens. A lot of people would create boxes that were say 800 pixels high. Doesn't sound all that big, but when you're looking at it on a laptop, the box would be too large and the top and bottom would cut off.

    It's one of those things that looks like a good idea on the surface, but generally isn't upon closer inspection.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  8. #7
    Member Cranavvo's Avatar
    Join Date
    Sep 2013
    Location
    St. Helens, England
    Posts
    70
    Member #
    37189
    Liked
    11 times
    Quote Originally Posted by TheGAME1264 View Post
    Probably because it doesn't fit in all screens. A lot of people would create boxes that were say 800 pixels high. Doesn't sound all that big, but when you're looking at it on a laptop, the box would be too large and the top and bottom would cut off.

    It's one of those things that looks like a good idea on the surface, but generally isn't upon closer inspection.
    Yeah- screen resolution is always a major factor when it comes to alignment. It's why I never really use percentages as widths or heights because judging on the browser dimensions / screen resolution my content would change drastically.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:44 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com