Monday, September 13, 2010

Content margins and padding in CSS

Page margins and padding are easy to define using CSS. By setting these values once in an
external file, you can update settings site-wide by uploading an amended style sheet rather
than every single page on your site that has an amended body tag.
Furthermore, in terms of page weight, CSS is more efficient. If using old methods, to cater
for all browsers, you set the following body attributes:
<body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0"
å bottommargin="0" rightmargin="0">
The equivalent in CSS is the following:
body {
margin: 0;
padding: 0;
}
The reason both margin and padding are set to 0 is because some browsers define a
default padding value. Therefore, even if you set all body margins to 0, there would still be
a gap around your page content. Setting both the margin and padding to 0 in the body rule
ensures that all browsers display your content with no gaps around it.

No comments:

Post a Comment