Html 指定的 body CSS 宽度是否安全?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4986836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:42:26  来源:igfitidea点击:

specified body CSS width is safe?

htmlcsswidth

提问by Andrew Rumm

Now very often content with a certain size centered.

现在经常满足于以一定的尺寸居中。

<html>
<head>
  <style type="text/css">
    #content { margin: auto; width: 960px;}
  </style>
</head>
<body>
   <div id="content">Blah!</div>
</body>
</html>

Is it safe to not use a wrapper for alignment and size, and apply it directly to a bodytag? Like this:

不使用包装器进行对齐和大小,并将其直接应用于body标签是否安全?像这样

<html>
<head>
   <style type="text/css">
      body { margin: auto; width: 960px;}
   </style>
</head>
<body>
   Blah
</body>
</html>

采纳答案by flying sheep

The size is safe, however the margin: auto-centering isn't completely.

大小是安全的,但是margin: auto-centering 并不完全。

You have to add text-align: centerto the body style to center it in IE6, too. (Yeah, I know, it totally makes no sense, but that's hoe IE6 works)

您也必须添加text-align: center到 body 样式以使其在 IE6 中居中。(是的,我知道,这完全没有意义,但这就是 IE6 的工作原理)