I'm using margin: 0 auto;
to center the contents of my pages.
Recently I discovered that using an automatic margin on a body
has the same visual effect as an automatic margin on a (wrapper) div
.
<!DOCTYPE>
<html>
<head>
<style>
div#wrapper {
margin: 0 auto;
width: 60%;
}
</style>
</head>
<body>
<div id="wrapper">
<!-- Rest of page. -->
</div>
</body>
</html>
Compared to;
<!DOCTYPE>
<html>
<head>
<style>
body {
margin: 0 auto;
width: 60%;
}
</style>
</head>
<body>
<!-- Rest of page. -->
</body>
</html>
It seems better as it removes an (unneccesary) element. Are there any pitfalls that need to be considered when using this approach?