| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <!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>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- #box {
- /* height: 400px; */
- /* 溢出隐藏 */
- /* overflow: auto; */
- }
- #box div {
- /* margin-top: 10px; */
- /* float: left; */
- /* margin-left: 10px; */
- }
- #box1 {
-
- width: 200px;
- height: 200px;
- float: left;
- background: red;
- }
- #box2 {
-
- width: 200px;
- height: 200px;
- float: left;
- background: rgb(0, 255, 217);
- }
- #box3 {
-
- width: 200px;
- height: 200px;
- float: left;
- background: rgb(225, 255, 0);
- }
- #box4 {
-
- width: 200px;
- height: 200px;
- float: left;
- background: #00f;
- }
- #box5 {
-
- width: 200px;
- height: 200px;
- float: left;
- background: #0f0;
- }
- #box6 {
-
- width: 200px;
- height: 200px;
- float: left;
- background: rgb(255, 0, 212);
- }
- #empty {
- clear: both;
- }
- .clearfix::after {
- content: "";
- display: block;
- clear: both;
- }
- </style>
- </head>
- <body>
- <!--
- 浮动导致的问题?
- 使用浮动标签的父元素的高度塌陷
- 清浮动:
- 1.溢出隐藏法
- 在塌陷的父元素上添加overflow:hidden/auto属性
- 2.伪元素清浮动
- .clearfix::after {
- content: "";
- display: block;
- clear: both;
- }
- 将 属性名添加到高度塌陷的父级盒子上
- 3.额外标签法
- 在浮动的同级添加一个空盒子 然后给这个盒子一个样式clear:both/left/right/none
- -->
- <div>
- <div id="box" class="clearfix">
- <div id="box1"></div>
- <div id="box2"></div>
- <div id="box3"></div>
- <div id="box4"></div>
- <div id="box5"></div>
- <div id="box6"></div>
- <!-- <div id="empty"></div> -->
- </div>
- <h1>你好</h1>
- </div>
- </body>
- </html>
|