Do a lot of people use container divs around all their pages? What I mean is do a lot of people put a div around the whole html body and then center the div in the normal?

  • If they dont then how do they get the pages to adjust to the window? Do they just use liquid design? canyonchase1 almost 7 years ago

1 answer

o.k.w 2355
2
points
This was chosen as the best answer

It's a good practice to have a container, not neccessary a single main one that contains everything else in the page.

In fact, some of the W3C standards do not allow textual content without a container.

The following example is not compliant to some strict standards.

<body>
hello world!
</body>

This however do:

<body>
    <div>hello world!</div>
</body>

You are right a lot of people like to have a master <DIV> to place everything inside for the sake of 'better' control over the layout. Be it fluid or fixed-width etc. However you don't have to do it this way to achieve the same result for some layouts.

Here's an example for a fixed width layout with a header, content and a open centered footer without using a master <DIV>:

CSS:

div.root {
    margin: 0 auto; //centering the root div
    padding: 0;
    width: 600px; //fixed the width
    outline: solid 1px #999999; 
}
div.header {
    height: 80px;
    font-size: 20px;
    font-weight: bold;
    background-color: #999999;
    color: #ffffff;
}
div.maincontent {
    min-height: 400px;
}
div.footer {
    height: 30px;
    text-align: center;
    padding-top: 10px;
}

HTML:

<div class="root header">header</div>
<div class="root maincontent">hello world</div>
<div class="footer">footer</div>
Answered almost 7 years ago by o.k.w
  • k thx. btw when your doing a fluid design, do you have to have everything on the page in percentages, even the text? canyonchase1 almost 7 years ago
  • There's a high chance percentage will be use though I can think of some fluid layouts which don't. o.k.w almost 7 years ago
  • Awesome answer, o.k.w. Very thorough. I wish I could give you two points for it, but since I can't... +1 Abinadi Ayerdis almost 7 years ago