2 replies [Last post]
Satan
Offline
Regular
Last seen: 18 years 12 weeks ago
Timezone: GMT-5
Joined: 2004-09-07
Posts: 14
Points: 0

Hi guys,

I'm wondering if I should explicitly set some values even though I don't have to (in IE6 at least). Here is some code:

MyStyle.css

#container {
 width: 100%;
 margin: 0;
 padding: 0;
}

MyPage.htm

<body>
<div id="container">
 ...
 ...
</div>
</body>

Alright, if I don't set the 'width' it works fine, but I can also set it explicitly to 'width: 100%' and 'width: auto', I remember reading that it's a good idea to set the 'dimension' to avoid weird behavior; so should I set it like that ? And what's better to use, the 'auto' or the '100%' in this situation ?

Same for the margins and padding, should I be explicitly setting those to '0' ?

Any guidence would be appreciated.

Take care,
Satan

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 1 day ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

Explicitly Set Widths (and Margins) ?

Hi Satan,
By default block elements like div take up the whole width.
I think the only time you need to explicitly define the width is if the div is floated.

Hope that helps

Root
Offline
Enthusiast
Brighton UK
Last seen: 15 years 43 weeks ago
Brighton UK
Joined: 2004-09-08
Posts: 76
Points: 0

Explicitly Set Widths (and Margins) ?

With the important caveat that some OS do not fill the full visible screen area unless you set margin and padding to zero as you have done.

No class, little style and a lotta division.