批改狀態(tài):合格
老師批語:寫得不錯, 就是忘了寫總結了
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>Document</title> <style> .box1 { width: 150px; border: 5px solid rgb(40, 9, 211); overflow: hidden; /* 主要用來清浮動,消除子級浮動給父級元素高度折疊的影響 */ } .box2 { width: 150px; height: 150px; background: rgb(5, 219, 41); float: left; } </style> </head> <body> <div class="box1"> <div class="box2"></div> </div> </body> </html>
點擊 "運行實例" 按鈕查看在線實例
2. 實例演示三列布局的實現(xiàn)原理( 絕對定位實現(xiàn), 浮動定位實現(xiàn))
2.1絕對位置實現(xiàn)三列布局
<!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> .box { width: 800px; overflow: hidden; background: burlywood; margin: 0 auto } .nav { width: 800px; height: 50px; background: aquamarine; float: left; } .footer { width: 800px; height: 50px; background: rgb(207, 158, 21); float: left; } .main { width: 800px; min-height: 600px; float: left; background: rgb(31, 10, 223); position: relative; } .left { width: 200px; height: 600px; background: brown; position: absolute; left: 0; top: 0; } .right { width: 200px; height: 600px; background: rgb(7, 190, 53); position: absolute; right: 0; top: 0; } .content { margin: 0 200px; background: beige; height: 600px; } </style> </head> <body> <div class="box"> <div class="nav">導航</div> <div class="main"> <div class="left">左邊</div> <div class="content">中間</div> <div class="right">右邊</div> </div> <div class="footer">底部信息</div> </div> </body> </html>
點擊 "運行實例" 按鈕查看在線實例
2.2 浮動定位實現(xiàn)布局
<!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> .box { width: 800px; overflow: hidden; background: burlywood; margin: 0 auto } .nav { width: 800px; height: 50px; background: aquamarine; float: left; } .footer { width: 800px; height: 50px; background: rgb(207, 158, 21); float: left; } .main { width: 800px; min-height: 600px; float: left; background: rgb(31, 10, 223); } .left { width: 200px; height: 600px; background: brown; float: left; } .right { width: 200px; height: 600px; background: rgb(7, 190, 53); float: left; } .content { width: 400px; height: 600px; float: left; background: beige; } </style> </head> <body> <div class="box"> <div class="nav">導航</div> <div class="main"> <div class="left">左邊</div> <div class="content">中間</div> <div class="right">右邊</div> </div> <div class="footer">底部信息</div> </div> </body> </html>
點擊 "運行實例" 按鈕查看在線實例
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號