清除浮动方法.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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>Document</title>
  7. <style>
  8. .main {
  9. /* overflow: hidden; */
  10. }
  11. .one {
  12. width: 200px;
  13. height: 200px;
  14. border: 1px solid #f00;
  15. /* background: #00f; */
  16. float: left;
  17. }
  18. .two {
  19. width: 200px;
  20. height: 200px;
  21. border: 1px solid #f00;
  22. /* background: #f0f; */
  23. float: left;
  24. }
  25. .three {
  26. width: 200px;
  27. height: 200px;
  28. border: 1px solid #f00;
  29. /* background: #f0f; */
  30. float: left;
  31. }
  32. .four {
  33. width: 200px;
  34. height: 200px;
  35. float: left;
  36. background: #00f;
  37. }
  38. .clearfix::after {
  39. content: "";
  40. display: block;
  41. clear: both;
  42. }
  43. /* .empty {
  44. clear: left;
  45. } */
  46. /* div {
  47. width: 200px;
  48. height: 200px;
  49. background: #f00;
  50. margin-top: 10px;
  51. display: inline-block;
  52. }
  53. span {
  54. width: 100px;
  55. height: 100px;
  56. margin-top: 10px;
  57. background: #00f;
  58. display: inline-block;
  59. } */
  60. </style>
  61. </head>
  62. <body>
  63. <!--
  64. 清浮动方法
  65. 1.溢出隐藏法
  66. 在父级盒子上 添加overflow:hidden(隐藏)| auto(自适应)
  67. 2.额外标签法
  68. 在与浮动同级上添加一个空盒子,单独添加属性clear:both|none|left|right
  69. 3.伪元素清浮动
  70. .clearfix::after {
  71. content: "";
  72. display: block;
  73. clear: both;
  74. }
  75. 添加到浮动的父级元素上
  76. -->
  77. <!--
  78. 块级元素 display: block
  79. 行内元素 display: inline
  80. 行内块元素 display: inline-block
  81. -->
  82. <!--
  83. 特殊符号
  84. &nbsp; 半格
  85. &gt; 大于号
  86. &lt; 小于号
  87. &reg; 商标
  88. -->
  89. <!-- <div></div>
  90. <div></div>
  91. <span>1</span>
  92. <span>2</span> -->
  93. &gt;
  94. &lt;
  95. &reg;
  96. <div class="main clearfix">
  97. <div class="one">1</div>
  98. <div class="two">2</div>
  99. <div class="three">3</div>
  100. <div class="four">4</div>
  101. <!-- <div class="empty"></div> -->
  102. </div>
  103. </body>
  104. </html>