Is it bad or totally wrong to get a horizontally centered page by tuning CSS properties of html tag?
css code snippet:
<style type="text/css">
html
{
width: 1200px;
margin: 0px auto;
background-color: Gray;
}
body
{
background-color: red;
}
</style>
html code snippet:
<body>any contents go here...</body>
The
htmlis the father of every element in the page. If it becomes centered, let’s say you want to position something absolutely at the top left/right of your entire page. It will now become relative to the centeredhtmlelement, most likely… and it would be a pain having to offset that effect, which is why I don’t recommend doing so.This is why it’s better to center at least the body or a div wrapper.
EDIT: It seems like the AP’d element will be relative to the entire viewport in my actual test ( in Fx 3 ), but even so it could be inconsistent cross browser and inconsistent with IE.
You’re guaranteed things will go right by centering the wrapper.