具體步驟:
1.設置基本樣式
2.聖盃佈局是一種相對佈局,首先設置父元素container的位置:
3.將主體部分的三個子元素都設置左浮動
4.設置main寬度爲width:100%,讓其單獨佔滿一行
5.設置left和right 負的外邊距
6.接下來只要把left和right分別移動到這兩個留白就能夠了。能夠使用相對定位移動 left和right部分。html
代碼以下:瀏覽器
<!doctype html> <html> <head> <meta charset="utf-8"/> <title>聖盃佈局</title> <style> body{ margin:0; } .box{ margin:0 auto; width:900px; height:300px; background-color:orange; padding:0 200px; } .left{ width:200px; height:300px; background-color:red; float:left; margin-left:-100%; position:relative; left:-200px; } .center{ width:100%; height:300px; background-color:pink; float:left; } .right{ width:200px; height:300px; background-color:blue; float:left; margin-left:-200px; position:relative; right:-200px; } </style> </head> <body> <div class="box"> <div class="center"></div> <div class="left"></div> <div class="right"></div> </div> </body> </html>
效果圖:佈局
代碼以下:spa
<!doctype html> <html> <head> <meta charset="utf-8"/> <title>雙飛翼佈局</title> <style> body{ margin:0; } .box{ margin:0 auto; width:900px; height:300px; background-color:orange; } .warp{ margin:0 200px; } .left{ width:200px; height:300px; background-color:red; float:left; margin-left:-100%; } .center{ width:100%; height:300px; background-color:pink; float:left; } .right{ width:200px; height:300px; background-color:blue; float:left; margin-left:-200px; } </style> </head> <body> <div class="box"> <div class="center"> <div class="warp"></div> </div> <div class="left"></div> <div class="right"></div> </div> </body> </html>
效果圖:code