12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- <style>
- #part1 {
- float: left;
- width: 200px;
- height: 200px;
- margin-top: 10px;
- background: red;
- }
- #part2 {
- float: left;
- width: 200px;
- height: 200px;
- margin-top: 10px;
- background: yellow;
- }
- #part3 {
- float: left;
- width: 200px;
- height: 200px;
- margin-top: 10px;
- background: blue;
- }
- #part4 {
- float: left;
- width: 200px;
- height: 200px;
- margin-top: 10px;
- background: pink;
- }
- #part5 {
- float: left;
- width: 200px;
- height: 200px;
- margin-top: 10px;
- background: purple;
- }
- /* .box {
- overflow: auto;
- } */
- /* .aa {
- clear: left;
- } */
- #clearfix::after {
- content: "";
- display: block;
- clear: both;
- }
- </style>
- </head>
- <body>
- <!--
- 1.溢出隐藏法:
- 在浮动的父级盒子上添加overflow:hidden|auto属性
- 2.额外标签法:
- 在浮动同级添加空盒子 给该盒子添加样式:clear:both |left |right |none
- 3.伪元素清浮动
- #clearfix::after {
- content: "";
- display: block;
- clear: both;
- }
- 将其添加到高度塌陷的父级盒子上
- -->
- <div class="box" id="clearfix">
- <div id="part1"></div>
- <div id="part2"></div>
- <div id="part3"></div>
- <div id="part4"></div>
- <div id="part5"></div>
- <!-- <div class="aa"></div> -->
- </div>
- </body>
- </html>
|