Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Centred fixed-width layout

Options
  • 27-02-2008 8:08pm
    #1
    Registered Users Posts: 6,465 ✭✭✭


    Very basic question. I have a 3 fixed column layout which I want centred when the viewport is wider than the columns. Can I do this in CSS? Or do I need a script which I presume just sets the left of the containing <div> whenever the window is resized?


Comments

  • Registered Users Posts: 2,934 ✭✭✭egan007


    Just set the margins in the surrounding div as follows

    #wrap {
    margin:0px auto 0px auto;
    }


  • Registered Users Posts: 6,465 ✭✭✭MOH


    Ah brilliant, knew there had to be an easy way!

    Thanks a million.


  • Registered Users Posts: 35,524 ✭✭✭✭Gordon


    I think you have to add text-align:center for IE5/6 also.


  • Registered Users Posts: 2,934 ✭✭✭egan007


    The above works fine across the board.
    Use it all the time


  • Registered Users Posts: 706 ✭✭✭DJB


    or the shorter code of:

    #wrap {margin: 0 auto;}

    Not much shorter but I always like to use shorthand as much as possible. Yeah, it works across the board. :D


  • Advertisement
  • Registered Users Posts: 802 ✭✭✭charybdis


    Or skip the extra div:
    
    body {
      width: whatever;
      margin-left: auto;
    }
    
    


Advertisement