Which web browsers apply a default CSS margin/padding on the body element by default?

前端 未结 2 1405
孤城傲影
孤城傲影 2021-01-15 22:33

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

I know Google Chrome applies a 8px margin, and I\'ve heard that other brow

相关标签:
2条回答
  • 2021-01-15 23:01

    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.

    <!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>
    
    0 讨论(0)
  • 2021-01-15 23:12

    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.

    0 讨论(0)
提交回复
热议问题