Web Design Articles

Body padding and margin


Russ Weakley
02-Oct-03

How do you force content to sit in the very top left corner of the browser window? In the old days we used to use invalid hacks like:

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

Now, it is far more common to see developers using CSS based methods like:

body
{
margin: 0;
padding: 0;
}

But why do you need margin and padding? The reason is that browsers use different methods to set their default indentation on the body element.

If body { padding: 0; } is used, only Opera (both Mac and Windows) will set items into the top left corner of the window. See sample 1 - body padding.

If body { margin: 0; } is used, all other standards compliant browsers (excluding Opera) will set items into the top left corner of the window. See sample 2 - body margin.

The best way to set items into the top left corner of the window is to use body { margin: 0; padding: 0; } which will work for all standards compliant browsers. See sample 3 - body padding and margin.





 

 

why-css-is-good-for-google
using-relatve-font-sizes
random-content-rotation
web-design-xhtml-1-1
web-design-resources
accessibility-intro
web-design-xhtml-2-1
why-internet-marketing
xhtml-latin-1-character-references
google-updates
google-dance
css-positioning-properties
fancy-paragraphs
bob-regan-macromedia-accessibility
web-design-technologies
wrox-beginning-php-4-chapter-3-1
julie-howell-rnib-accessibility
handy-hints-web-design
mod_accessibility
pagerank-1
search-engine-crawling
Definition lists - misused or misunderstood.html
Accessible Data Tables
Developing sites for users with Cognitive disabilities and learning difficulties
An Accessibility Frontier Cognitive disabilities and learning difficulties
Inline elements and padding
Basic webstandards Workshop
Internet Explorer and column collapse
Building a page template in CSS - a step by step tutorial
Remote control CSS
Colored boxes - one method of building full CSS layouts
Replicating a Tree table
Creating a graph using percentage background images
Simple, accessible external links
Simple, accessible more links
Styling abbreviations and acronyms
 Web standards checklist
Floated items inside containers
Liquid layouts the easy way
Two columns with color
CSS Centering - fun for all!
Body padding and margin
List inheritance and Descendant Selectors
Taming the Taming lists model
Headings as images - The Lindsay method
Ideal line length for content
Validating Australian Museum Online
Styling the hr element
Styling and font family names that contain whitespace
Sample CSS Page Layouts