簡體   English   中英

為什么將車身高度設置為100%會自動將寬度設置為100%?

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

我注意到將html和body高度設置為100%,body的寬度似乎會自動設置為100%(即使在CSS規則中沒有出現),為什么呢?

<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

將這些元素的高度設置為任何值(甚至根本不設置)都不會更改其寬度,由於它們是block元素,默認情況下為100%。

您可以通過檢查瀏覽器中的任何HTML頁面並查找屬性display: block;來驗證這一點display: block; ,由user agent stylesheet (您的瀏覽器)在這些元素中定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM