Blogger Information
Blog 56
fans 1
comment 0
visits 62304
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
元素大小重新计算
零龙
Original
589 people have browsed it

元素大小重新计算


  • box-sizing
    语法:box-sizing: content-box|border-box|inherit;

描述
content-box 宽度和高度分别应用到元素的内容框。
border-box 为元素设定的宽度和高度决定了元素的边框盒。
inherit 规定应从父元素继承 box-sizing 属性的值。
  • 默认值:content-box

实例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>元素大小计算方式</title>
  7. <style>
  8. /* 样式初始化 */
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. div{
  15. width: 200px;
  16. height: 200px;
  17. margin: 20px;
  18. border: 3px solid #666;
  19. }
  20. div:first-of-type
  21. {
  22. background-color: green;
  23. background-clip: content-box;
  24. padding: 50px;
  25. box-sizing: border-box;
  26. }
  27. div:last-of-type{
  28. background-color: lightskyblue;
  29. background-clip: content-box;
  30. padding: 50px;
  31. box-sizing: content-box;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div></div>
  37. <div></div>
  38. </body>
  39. </html>

实例效果图


总结


  • 当box-sizing:border-box;盒子不会随着padding变化。
  • 当box-sizing: content-box; 盒子随着padding变化。
  • 如图:
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:下次将当天作业全部写完再提交
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