Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Centred fixed-width layout

  • 27-02-2008 07:08PM
    #1
    Registered Users, Registered Users 2 Posts: 6,477 ✭✭✭


    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, Registered Users 2 Posts: 2,934 ✭✭✭egan007


    Just set the margins in the surrounding div as follows

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


  • Registered Users, Registered Users 2 Posts: 6,477 ✭✭✭MOH


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

    Thanks a million.


  • Registered Users, Registered Users 2 Posts: 35,522 ✭✭✭✭Gordon


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


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


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


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 802 ✭✭✭charybdis


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


Advertisement
Advertisement