Please advice on the page alignment issue with CSS

Discussion in 'CSS' started by meet6669, Oct 8, 2007.

  1. #1
    I have a 14 inch monitor in which i tests my web pages. But when i load the pages in a larger monitor then i see the whole content of the page is by default aligned to the left side which i want to see aligned in the center. For example, the site godaddy.com and the full content when loaded in a big monitor aligns perfectly in the center and this what exactly I am looking for. I have tried the align=centre trick but what happens is that the text in the tables also gets centered . I dont want the text to be centered but only the table that holds the text ... I have posted this in other forums but received only vague instructions. I know basics of style sheet and I heard that this can be done with style sheets. I would really appreciate if some one could reply with a one by one step instructions. I do not want the text in the table to be centered bit only the table to be centered . If you take the website of godaddy.com in a large monitor then you can see the whole page is shown in the center. The text in the table is not centered. Can it be done with CSS ?. I hope i was able to explain my point
     
    meet6669, Oct 8, 2007 IP
  2. longhornfreak

    longhornfreak Well-Known Member

    Messages:
    2,067
    Likes Received:
    95
    Best Answers:
    0
    Trophy Points:
    140
    #2
    create a container and make it have

    margin: 0 auto;
    text-align: left;
     
    longhornfreak, Oct 8, 2007 IP
  3. DaveWoods

    DaveWoods Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Personally I tend to use

    
    body {
      width: 760px;
      margin: 0 auto;
    }
    
    Code (markup):
    It's not supported in IE5.x or below but I wouldn't really worry about IE5.x other than ensuring it's usable and accessible.

    If you need to support IE5.x then use the method as suggested by longhornfreak and then use text-align: center; within the CSS on the body.
     
    DaveWoods, Oct 9, 2007 IP
  4. Stretsh

    Stretsh Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Simple:

    body {
      text-align: center;
    }
    
    #container {
      width: 780px;
      margin: 0 auto;
      text-align: left;
    }
    Code (markup):
     
    Stretsh, Oct 9, 2007 IP
  5. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Stretsh, that only works with Internet Explorer 5.5 and older as far as I know.

    Try it in IE 6 or 7. You'll only see the text is aligned.

    However, you will still see it in CSS, but then it's only added for in case someone with IE5.5 shows up. The margin: 0 auto; is also being used on those same CSS sheets for all the other browsers in the world.
     
    Stomme poes, Oct 9, 2007 IP
  6. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #6
    ^ Huh?

    He has horizontal auto margins, and the text-align:left; would be applied to any element in #container, so it would work perfectly.
     
    soulscratch, Oct 9, 2007 IP
  7. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yes, and the text-align on the body is necessary for IE
     
    Arnold9000, Oct 9, 2007 IP
  8. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #8
    No. I would advise against it. IE7 just came out and the IE team is supposedly working on a new engine for IE.Next, why should we include hacks for old-ass browsers that don't have proper CSS support?

    This is my personal opinion, but I think we should NOT code for WIN IE5/ MAC IE 5.2 because chances are MOST sites break on those browsers ANYWAY, and the user will sooner or later get a different browser or get an upgraded version of the browser.
     
    soulscratch, Oct 9, 2007 IP
  9. Stretsh

    Stretsh Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Does it? Cause this is how I have been centering my pages a while now.

    Just to be sure I'm not crazy, I made a quick file:

    <style type="text/css" media=screen>
    body {
      text-align: center;
    }
    
    #container {
      width: 780px;
      margin: 0 auto;
      text-align: left;
      border: 2px solid #000;
    }
    </style>
    <body>
    <div id="container">This is a test</div>
    </body>
    Code (markup):
    Works in both IE6 and FF
     
    Stretsh, Oct 9, 2007 IP
  10. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Because if a customer is paying you, he doesn't want to hear from his customers that something is funky with his website.

    It's one line of code that doesn't appear to effect any other browsers or versions as long as a container div is used and the desired text alignment is set there. What happens with this in IE7? I don't have it yet.
     
    Arnold9000, Oct 9, 2007 IP
  11. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #11
    1. I can sort of agree with you on #1, but I personally don't like messy stylesheets so I'd feed that rule ONLY with a CC given to any version of IE below 6.

    2. It *DOES* effect all other browsers, it's just that you're resetting the effect by text-align:left; on your main wrapper.
     
    soulscratch, Oct 9, 2007 IP
  12. Stretsh

    Stretsh Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    A mean to an end.

    See point 1: The customer doesn't care about resetting of an effect. Anyone should see his website the way he wants it to be seen, so my personal preferences when it comes to coding don't count
     
    Stretsh, Oct 9, 2007 IP
  13. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #13
    The CC is as much hassle as the line of code itself. If one wants to add a comment next to it, fine.

    Right, so net effect is no effect. I'd rather do that and be a jack of all trades to everyone. Again, only one line of code, and if there is no text in your body, then it DOESN'T affect browsers at all because there is no text to style as that is all in the container. Therefore, other browsers just treat it as an unnecessary declaration that is ignored because there is no text to execute the declaration on.
     
    Arnold9000, Oct 9, 2007 IP
  14. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Sorry Stetsh, I didn't see your margin 0 auto for some reason and though you just had the text align.

    I've used it (text-align for 5.5) on one site because our stats show a few hangers on and they are likely to be old people (insurance site).
     
    Stomme poes, Oct 9, 2007 IP
  15. Stretsh

    Stretsh Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I usually don't care for older browsers either. I usually just check for IE6+ and FF and some other usual browsers, but if the focus group demands it, I do check it all.

    I personally wonder what other way there is to get this done when you DO need to think of older browsers.
     
    Stretsh, Oct 9, 2007 IP
  16. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #16
    There is (was?) someone here who really advocated seperate stylesheets, but I think adding the stuff for the older browsers and writing the html to work well enough without css is the best thing. When I got mulitple IEs from tredosoft, I kept 3.1 because I can see the site without CSS on a browser that I used to use long long ago. I have Lynx too but the damn screen is too small and I haven't figured out how to configure that.
     
    Stomme poes, Oct 9, 2007 IP