123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #div1{
- width: 200px;
- height: 200px;
- background: #f00;
- float: left;
-
- }
- #div2{
- width: 200px;
- height: 200px;
- background: #0f0;
- float: left;
- }
- h1{
- height: 100px;
- background: orchid;
- }
- #div0{
- /* height: 200px; */
- /* overflow: hidden; */
- }
- /* 伪元素选择器 after在内部的后边生成元素 */
- .clearfix::after{
- content:''; /*after元素必须有*/
- display: block;
- clear: both;
- }
- </style>
- </head>
- <body>
- <!-- 浮动 left左浮动 |right有浮动 |none不浮动
- 浮动的元素特点: 脱离文档流 空间释放;
- 子元素浮动导致父元素塌陷问题
- 解决方式:
- 1 给父元素添加一个高度 (已知父元素的高度)
- 2 给父元素添加一个overflow:hidden
- 3 在浮动的元素下边添加一个 块级元素,通过clear 清除浮动
- 4 通过clearfix::after{
- content:'';
- display:block;
- clear:both
- }
- -->
- <div id="div0" class="clearfix">
- <div id="div1"></div>
- <div id="div2"></div>
- <!-- clear:left |right |both -->
- <!-- <div style="clear:both ;"></div> -->
- <!-- 自动生成一个块元素 -->
- </div>
- <h1></h1>
-
-
- </body>
- </html>
|