當你設定一個元素樣式為 box-sizing: border-box;,這個元素的內距和邊框將不會增加元素本身的寬度。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Test box-sizing</title>
    <style>
    .simple {
        width: 500px;
        margin: 20px auto;
        border: solid red 40px;
        /*-webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;*/
        box-sizing: border-box;
    }
    
    .fancy {
        width: 500px;
        margin: 20px auto;
        padding: 50px;
        border: solid blue 10px;
        /*-webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;*/
        box-sizing: border-box;
    }
    </style>
</head>

<body>
    <div class="simple">我們現在一樣大小了!
    </div>
    <div class="fancy">喔耶!</div>
</body>

</html>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2021-09-05
  • 2021-10-26
  • 2021-11-30
  • 2021-11-24
  • 2022-02-08
相关资源
相似解决方案