简体   繁体   中英

why setting the height of the body to 100% sets automatically the width to 100%?

I noticed that setting the html and body height to 100%, the body's width seems to be set automatically to 100% (even if it does not appear among the css rules), why?

<html>
  <head
    <title>full screen</title>
    <style>
    html, body{
       margin: 0;
       height: 100%;
       background-color: rgb(200,50,50);
    }
    </style>
  </head>
  <body>

  </body>
</html>

http://jsbin.com/wocini/1/edit?html,css,output

Setting these elements' heights to any value (or even not setting it at all) doesn't change their width, which is 100% by default due to them being block elements.

You can verify this by inspecting any HTML page in your browser and looking for the property display: block; , defined by user agent stylesheet (your browser), in these elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM