默认的``保证金有多宽?

时间:2022-03-22 22:42:37

What’s the default margin that 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 px or %, etc.).

HTML为其标记设置的默认边距是多少?我注意到有一些自动保证金,但我想知道是否有人知道它是多少(以及它是在px还是%等)。

2 个解决方案

#1


28  

In most major browsers, the default margin is 8px on all sides. It is defined in pixels by the user-agent-stylesheet your 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.

有些浏览器允许您创建和使用自己的用户代理样式表,但是如果您正在开发一个网站,我建议不要更改它,因为您的用户很可能没有修改过的样式表,然后会看到不同的页面比你做的。

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。它会将许多默认值重置为跨浏览器保持一致。

#2


1  

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,可以快速获取任何元素的计算细节。

#1


28  

In most major browsers, the default margin is 8px on all sides. It is defined in pixels by the user-agent-stylesheet your 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.

有些浏览器允许您创建和使用自己的用户代理样式表,但是如果您正在开发一个网站,我建议不要更改它,因为您的用户很可能没有修改过的样式表,然后会看到不同的页面比你做的。

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。它会将许多默认值重置为跨浏览器保持一致。

#2


1  

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,可以快速获取任何元素的计算细节。