前端布局分為單列布局、雙列布局、三列布局,而三列布局中最經(jīng)典的布局方式就是雙飛翼布局和圣杯布局。
今天我來介紹一下這兩種布局方式:
一、雙飛翼布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>雙飛翼布局</title> <style type="text/css"> .header,.footer{ width: 100%; height: 60px; background-color: lightgray; } .content{ width: 1000px; min-height: 100%; background-color: gray; margin: auto; text-align: center; line-height: 60px; } .footer{ clear:both; } .contaiter{ width: 1000px; margin: auto; background-color: yellow; overflow: hidden; } .wrap{ width: 100%; float: left; background-color: cyan; } .wrap .main{ height: 650px; background-color: wheat; margin-left: 200px; margin-right: 200px; } .left{ width: 200px; height: 650px; float: left; background-color: lightskyblue; margin-left: -100%; } .right{ width: 200px; height: 650px; float: left; background-color: lightgreen; margin-left: -200px; } </style> </head> <body> <div class="header"> <div class="content">網(wǎng)站頭部</div> </div> <div class="contaiter"> <div class="wrap"> <div class="main">中間</div> </div> <div class="left">左側(cè)</div> <div class="right">右側(cè)</div> </div> <div class="footer"> <div class="content">網(wǎng)站底部</div> </div> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
二、圣杯布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>圣杯布局</title> <style type="text/css"> .header, .footer { width: 100%; height: 60px; background-color: lightgray; } .footer { clear: both; } .content { width: 1000px; height: 100%; background-color: gray; margin: auto; text-align: center; line-height: 60px; } .container { width: 600px; background-color: yellow; margin:auto; overflow: hidden; padding:0 200px; } .container .main { min-height: 650px; width: 100%; float:left; background-color: wheat; } .container .left { width: 200px; min-height: 650px; float:left; margin-left: -100%; position: relative; left: -200px; background-color: lightskyblue; } .container .right { width: 200px; min-height: 650px; float:left; margin-left:-200px; position: relative; right:-200px; background-color: lightgreen; } </style> </head> <body> <div class="header"> <div class="content">網(wǎng)站頭部</div> </div> <div class="container"> <div class="main">主體</div> <div class="left">左側(cè)</div> <div class="right">右側(cè)</div> </div> <div class="footer"> <div class="content">網(wǎng)站底部</div> </div> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
運(yùn)行結(jié)果:
兩種布局方式的運(yùn)行結(jié)果都是一樣的
手抄代碼:
總結(jié):
雙飛翼布局和圣杯布局的區(qū)別:雙飛翼布局通過margin來實(shí)現(xiàn),圣杯布局通過padding來實(shí)現(xiàn)。
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號