In my fixed-width website, I have a layout similar to this:
<div id="wrapper">
<header>...</header>
<div id="content">...</div>
<footer>...</footer>
</div>
And my CSS is similar to this:
#wrapper {
width: 700px;
margin-left: auto;
margin-right: auto;
}
Styling the <body>
tag the same way also works, and it makes my code more readable, as I have less nested <div>
tags.
Is applying margins and a fixed with to the <body>
a safe idea?
It is perfectly safe, body
is an HTML element like all the others.
For your layout, you might still want to use #wrapper
(seems like a fixed width layout), because you might want to set a background for body
(or do something with the visible "empty" space).