通过调整html标签的CSS属性来获得水平居中的页面是坏还是完全错误? [英] Is it bad or totally wrong to get a horizontally centered page by tuning CSS properties of html tag?
问题描述
通过调整html标签的CSS属性来获取水平居中的网页是不好还是完全错误?
Is it bad or totally wrong to get a horizontally centered page by tuning CSS properties of html tag?
css代码段 / p>
css code snippet:
<style type="text/css">
html
{
width: 1200px;
margin: 0px auto;
background-color: Gray;
}
body
{
background-color: red;
}
</style>
html代码段:
<body>any contents go here...</body>
推荐答案
html
是页面中每个元素的父亲。如果它变为中心,我们假设你要将某个东西绝对放置在整个页面的左上/右边。它现在将变成相对于中心的 html
元素,很可能...,这将是一个痛苦,必须抵消这种效果,这就是为什么我不推荐做所以。
The html
is 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 centered html
element, most likely... and it would be a pain having to offset that effect, which is why I don't recommend doing so.
这就是为什么最好至少以body或div包装为中心。
This is why it's better to center at least the body or a div wrapper.
EDIT :在我的实际测试中(在Fx 3中),看起来AP'd元素将相对于整个视口,但是即使这样也可能是不一致的跨浏览器和与IE不一致。
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.
这篇关于通过调整html标签的CSS属性来获得水平居中的页面是坏还是完全错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!