Html 默认的 `<body>` 边距有多宽?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13127887/
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 03:37:24  来源:igfitidea点击:

How wide is the default `<body>` margin?

htmlcssmargin

提问by John

What's the default marginthat HTML sets for its <body>tag? I noticed that there's some automatic margin, but I'm wondering if anyone knows how much it is (and whether it's in pxor %, etc.).

marginHTML 为其<body>标签设置的默认值是什么?我注意到有一些自动保证金,但我想知道是否有人知道它是多少(以及它是否在px%等)。

回答by Jon Egeland

In most major browsers, the default margin is 8pxon all sides. It is defined in pixels by the user-agent-stylesheetyour browser provides.

在大多数主要浏览器中,默认边距是8px所有边。它由user-agent-stylesheet您的浏览器提供的像素定义。

Some browsers allow you to create and use your own user-agent-stylesheet, but if you are developing a website, I would recommend staying away from changing this, since your users most likely will not have a modified stylesheet and would then see a different page than you do.

某些浏览器允许您创建和使用自己的user-agent-stylesheet,但是如果您正在开发一个网站,我建议您不要更改它,因为您的用户很可能不会修改样式表,然后会看到与您不同的页面。

If you want to change it, you can just do this:

如果你想改变它,你可以这样做:

body {
  margin: 0px;
  padding: 0px;
  ...
}

But if you have a large project and want to be more complete, use normalize.css. It resets a lot of default values to be consistent across browsers.

但是,如果您有一个大型项目并希望更完整,请使用normalize.css。它重置了许多默认值以在浏览器之间保持一致。

回答by Vickar

According to W3School's CSS reference,the default properties and values for a body tag are,

根据W3School 的 CSS 参考,body 标签的默认属性和值是,

body{ display : block; margin : 8px; }

And one can quickly get the computed details of any element by accessing the Computed Pane in the Chrome Dev tools.

通过访问Chrome Dev 工具中Computed Pane,您可以快速获取任何元素的计算详细信息