Blogger Information
Blog 47
fans 0
comment 3
visits 44876
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
box-sizing属性的作用
江流
Original
942 people have browsed it

div盒子的大小,在默认的情况下,我们设置好盒子大小后,盒子的真实大小要加上内边距和边框的宽度,真实大小不设置的数据要大一些。我们使用box-sizing属性,设置其值为border-box,盒子的真实大小就是我们设置的大小,盒子的内容大小会在设置大小的基础上减去内边距和边框的大小。

  • 不设置box-sizing属性代码:
    ```html
    <div class="box"></div>

    <style>
    .box {
    width: 300px;
    height: 300px;
    background-color: lawngreen;
    border-width: 20px;
    border-color: blue;
    border-style: dashed;
    padding: 10px;
    background-clip: content-box;
    </style>

  1. ![](https://img.php.cn/upload/image/363/997/482/1632479780916693.jpg)
  2. ![](https://img.php.cn/upload/image/733/859/278/1632479789140797.jpg)
  3. - 为盒子添加属性
  4. `box-sizing: border-box;`
  5. 代码如下:
  6. ```html
  7. <div class="box"></div>
  8. <style>
  9. .box {
  10. width: 300px;
  11. height: 300px;
  12. background-color: lawngreen;
  13. border-width: 20px;
  14. border-color: blue;
  15. border-style: dashed;
  16. padding: 10px;
  17. background-clip: content-box;
  18. box-sizing: border-box;
  19. </style>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post