默认情况下,哪些Web浏览器在body元素上应用默认的CSS边距/填充?

时间:2022-11-14 22:50:36

What web browsers apply a default CSS magin and/or padding on the body element by default?

默认情况下,哪些Web浏览器在body元素上应用默认的CSS magin和/或padding?

I know Google Chrome applies a 8px margin, and I've heard that other browsers have a default padding as well.

我知道Google Chrome应用了8px的保证金,我听说其他浏览器也有默认的填充。

Thanks!

谢谢!

2 个解决方案

#1


2  

Most browsers have default margin for body element. IE9 gives 15px vertical and 10px horisontal, Opera 11 gives 8px, yet this can and does change between versions, so you realy should incorporate css reset in your stylesheets, be it home-brew padding:0;margin:0;, Eric Meyer's or YUI.

大多数浏览器都有body元素的默认边距。 IE9提供15px垂直和10px水平,Opera 11提供8px,但这可以并且确实在版本之间改变,所以你真的应该在你的样式表中加入css reset,无论是家庭酿造填充:0;边距:0 ;, Eric Meyer's或者YUI。

#2


1  

Just use a simple test page, like this one, and try all the browsers you're interested in. From what I've seen, browsers seem to have a non-zero default for margin, and 0 for padding.

只需使用一个简单的测试页面,就像这个一样,然后尝试你感兴趣的所有浏览器。从我看到的情况来看,浏览器似乎有一个非零的默认值,0和填充。

<!doctype html>
<html>
  <head>
    <title>Default padding on body tag</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript">
        $(function(){
            $('#top').text($('body').css('margin-top'));
        });
    </script>
  </head>
  <body>
    margin-top: <span id="top"></span>
  </body>
</html>

#1


2  

Most browsers have default margin for body element. IE9 gives 15px vertical and 10px horisontal, Opera 11 gives 8px, yet this can and does change between versions, so you realy should incorporate css reset in your stylesheets, be it home-brew padding:0;margin:0;, Eric Meyer's or YUI.

大多数浏览器都有body元素的默认边距。 IE9提供15px垂直和10px水平,Opera 11提供8px,但这可以并且确实在版本之间改变,所以你真的应该在你的样式表中加入css reset,无论是家庭酿造填充:0;边距:0 ;, Eric Meyer's或者YUI。

#2


1  

Just use a simple test page, like this one, and try all the browsers you're interested in. From what I've seen, browsers seem to have a non-zero default for margin, and 0 for padding.

只需使用一个简单的测试页面,就像这个一样,然后尝试你感兴趣的所有浏览器。从我看到的情况来看,浏览器似乎有一个非零的默认值,0和填充。

<!doctype html>
<html>
  <head>
    <title>Default padding on body tag</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript">
        $(function(){
            $('#top').text($('body').css('margin-top'));
        });
    </script>
  </head>
  <body>
    margin-top: <span id="top"></span>
  </body>
</html>