Html <Body> 标签的边距和填充
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11066823/
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
Margin and Padding of <Body> Tag
提问by Arun Singh
I am writing a very simple HTML code which is listed below. Written in notepad and opening in IE-8 and Firefox (OS: Window Vista).
我正在编写一个非常简单的 HTML 代码,如下所示。用记事本编写并在 IE-8 和 Firefox(操作系统:Window Vista)中打开。
<html>
<body>
<table border="1"><tr><td>test</td></tr></table>
</body>
</html>
There is nothing special in the above code, It is creating some space from top left corner.
上面的代码没有什么特别的,它从左上角创建了一些空间。
Which can be easily removed by using the following code
可以使用以下代码轻松删除
<body style="margin:0; padding:0">
Now i have find out the default margin and padding, which is 4
for Firefox and different for IE-8.
现在我已经找到了默认的边距和填充,这是4
针对 Firefox 的,而对于 IE-8 则不同。
<body style="margin:4; padding:4">
I have some question on this scenario.
我对这个场景有一些疑问。
- Why this value is 4?
- From where this value is coming, is it saved somewhere?
- Can we modify (configurable) this default value?
- How these values are different for browsers?
- 为什么这个值是 4?
- 这个值来自哪里,是否保存在某个地方?
- 我们可以修改(可配置)这个默认值吗?
- 这些值对于浏览器有何不同?
Thanks.
谢谢。
采纳答案by Madara's Ghost
- First of all, it's probably
4px
and not4
. Second, that's just the way the browser vendor decided should be the default. - It is saved in the default browser stylesheets.
- You can, but you shouldn't. It differs with each browser. Google it!
How do I change default stylesheet on <insert browser here>?
- There probably are slight differences, you should be able to tell... by looking at the default stylesheets :)
- 首先,它可能是
4px
而不是4
。其次,这正是浏览器供应商决定的默认方式。 - 它保存在默认浏览器样式表中。
- 你可以,但你不应该。每个浏览器都不同。去谷歌上查询!
How do I change default stylesheet on <insert browser here>?
- 可能存在细微差别,您应该能够通过查看默认样式表来判断... :)
That difference is one of the main reasons we as designers use a CSS reset, to normalize all of the CSS awkwardness that follows different browser implementations.
这种差异是我们作为设计师使用 CSS 重置的主要原因之一,以规范不同浏览器实现后的所有 CSS 尴尬。
回答by lucideer
Browsers have built-in "sane defaults" for the CSS of most HTML elements - this just prevents your page looking completely unreadable if you have pure HTML without CSS, but they are of course intended to be overridden by your own CSS.
浏览器为大多数 HTML 元素的 CSS 内置了“合理的默认值”——这只是防止你的页面看起来完全不可读,如果你有没有 CSS 的纯 HTML,但它们当然打算被你自己的 CSS 覆盖。
The default browser styles are typically referred to as a "User Agent Style Sheet"- the following site is a good reference of the various peculiar UA sheets IE has had over the years and also provides ones for other browsers at the bottom:
默认浏览器样式通常称为“用户代理样式表”——以下站点很好地参考了 IE 多年来拥有的各种特殊 UA 表,并在底部为其他浏览器提供了这些表:
One method a lot of people use to "normalise"the defaults so you have the same starting point in all browsers is a "CSS Reset"- this is just a snippet of CSS that you place before your own CSS that sets all of the UA styles to the same thing. This is a well known one:
许多人用来“规范化”默认值的一种方法是“CSS 重置”,因此您在所有浏览器中都有相同的起点- 这只是您放置在您自己的 CSS 之前设置所有 UA 的 CSS 片段样式到同一件事。这是一个众所周知的:
回答by softcod.com
Try this
尝试这个
body{
line-height: 0
}
回答by Mr-29
Add this on top of your stylesheet
将此添加到样式表的顶部
*{margin:0px;padding:0px;}
This eliminated all differences in padding and margin across browsers.
这消除了跨浏览器的填充和边距的所有差异。