实例演示如何消除子元素浮动造成父元素高度折叠的影响
实例
<!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> .box { width: 200px; border: 5px dashed blue; overflow: hidden; } .box1 { width: 200px; height: 200px; background: lightgreen; float: left; } </style> </head> <body> <div class="box"> <div class="box1"></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>绝对定位布局</title> <style> .box { width: 1000px; margin: 0 auto; } .header { width: 100%; height: 50px; background: lightgrey; } .footer { width: 100%; height: 50px; background: lightgrey; } .main { background: lightblue; margin: 5px auto; position: relative; } .left { width: 200px; background: lightpink; min-height: 800px; position: absolute; left: 0; top: 0; } .right { width: 200px; background: yellow; min-height: 800px; position: absolute; right: 0; top: 0; } .content { min-height: 800px; background: lightseagreen; margin-left: 200px; margin-right: 200px; } </style> </head> <body> <div class="box"> <div class="header">网页头部</div> <div class="main"> <div class="left">左边</div> <div class="content">中间</div> <div class="right">右边</div> </div> <div class="footer">网页尾部</div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<!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> .box { width: 1000px; margin: 0 auto; } .header { width: 100%; height: 50px; background: lightgrey; } .footer { width: 100%; height: 50px; background: lightgrey; } .main { background: lightblue; margin: 5px auto; position: relative; overflow: hidden; } .left { background: lightcoral; width: 200px; min-height: 800px; float: left; } .right { background: lightseagreen; width: 200px; min-height: 800px; float: right; } .content { background: yellow; width: 600px; min-height: 800px; float: left; } </style> </head> <body> <div class="box"> <div class="header">网页头部</div> <div class="main"> <div class="left">左边</div> <div class="content">中间</div> <div class="right">右边</div> </div> <div class="footer">网页尾部</div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例