1、实例演示如何消除子元素浮动造成父元素高度折叠的影响。
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>浮动</title> <style> .box1 { width: 250px; border: 5px dashed rebeccapurple; overflow: hidden; } .box2 { width: inherit; height: 300px; background-color: lawngreen; float: left; } </style> </head> <body> <div class="box1"> <div class="box2"></div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
2、 实例演示三列布局的实现原理( 绝对定位实现, 浮动定位实现)。
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .box1 { width: 300px; height: 600px; background-color: lawngreen; } .box2 { width: 300px; height: 600px; background-color: lightcoral; position: relative; left: 300px; top: -600px; } .box3 { width: 300px; height: 600px; background-color: lightblue; position: relative; left: 600px; top: -1200px; } </style> </head> <body> <div class="parent"> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例