在此我們介紹幾種常用的響應(yīng)式布局方案。

實(shí)現(xiàn)的例子均是最常見(jiàn)的三欄布局、其中左右固定寬度、中間自適應(yīng)。

float布局

左右float

<body> <div cla" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > 幾種常用的響應(yīng)式布局方案

幾種常用的響應(yīng)式布局方案

時(shí)間:2023-09-02 23:12:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-09-02 23:12:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)

幾種常用的響應(yīng)式布局方案:

響應(yīng)式布局?

響應(yīng)式布局越發(fā)常見(jiàn)。

在此我們介紹幾種常用的響應(yīng)式布局方案。

實(shí)現(xiàn)的例子均是最常見(jiàn)的三欄布局、其中左右固定寬度、中間自適應(yīng)。

float布局

左右float

<body> <div class="left"></div> <div class="right"></div> <div class="center"></div></body><style> .left { background-color: pink; width: 100px; float: left; height: 500px; } .right { background-color: blueviolet; width: 100px; float: right; height: 500px; } .center { height: 500px; overflow: hidden; background-color: yellowgreen; }</style>流體布局

左右浮動(dòng)、中間使用margin

<body> <div class="left"></div> <div class="right"></div> <div class="center"></div></body><style> .left { background-color: pink; width: 100px; height: 500px; float: left; } .right { background-color: blueviolet; width: 100px; height: 500px; float: right; } .center { height: 500px; margin: 0 100px; background-color: yellowgreen; }</style>圣杯布局

全部浮動(dòng)。外層容器使用padding預(yù)留左右兩側(cè)。

左右兩欄通過(guò)負(fù)值margin和相對(duì)left移動(dòng)到同一行。

<body> <div class="container"> <div class="center"></div> <div class="left"></div> <div class="right"></div> <div style="clear: both;"></div> </div></body><style> .container { min-width: 800px; padding-left: 200px; padding-right: 200px; } .center { float: left; background-color: tomato; height: 500px; width: 100%; } .left { float: left; background-color: yellowgreen; width: 200px; height: 500px; position: relative; margin-left: -100%; left: -200px; } .right { float: left; background-color: pink; width: 200px; height: 500px; margin-left: -200px; position: relative; right: -200px; }</style>問(wèn)題:為什么設(shè)置左右是position:relative?

當(dāng)position:fixed/absolute時(shí)元素已脫離文檔流,float失效。

當(dāng)position:relative/static時(shí)元素正常位于文檔流,float有效。

雙飛翼布局

使用margin來(lái)?yè)伍_(kāi)寬度。

不必使用相對(duì)relative的位置,只需使用負(fù)值margin調(diào)整至同一欄即可

<body> <div class="container"> <div class="center"></div> </div> <div class="left"></div> <div class="right"></div></body><style> body{ min-width: 400px;; } .container { float: left; width: 100%; } .center { height: 500px; background-color: tomato; margin-left: 200px; margin-right: 200px; } .left { height: 500px; float: left; width: 200px; background-color: thistle; margin-left: -100%; } .right { height: 500px; float: left; width: 200px; background-color: turquoise; margin-left: -200px; }</style>

Flex彈性盒子布局

利用Flex進(jìn)行布局

<body> <div class="container"> <div class="center"></div> <div class="left"></div> <div class="right"></div> </div></body><style> .container { display: flex; } .center { flex: 1 1 200px; background-color: turquoise; height: 500px; } .left { order: -1; flex: 0 0 200px; height: 500px; background-color: thistle; } .right { flex: 0 0 200px; height: 500px; background-color: wheat; }</style>

Position定位布局

利用position。左右絕對(duì)定位到邊緣。中間使用margin撐開(kāi)。


<body> <div class="container"> <div class="left"></div> <div class="center"></div> <div class="right"></div> </div></body><style> .container { position: relative; } .center { margin: auto 200px; background-color: turquoise; height: 500px; } .left { position: absolute; left: 0; top: 0; width: 200px; height: 500px; background-color: thistle; } .right { position: absolute; right: 0; top: 0; width: 200px; height: 500px; background-color: wheat; }</style>網(wǎng)格Grid布局

使用CSS3新增的grid布局。

<body> <div class="container"> <div style="background-color: wheat;"></div> <div style="background-color: turquoise;"></div> <div style="background-color: tomato;"></div> </div></body><style> .container { display: grid; grid-template-columns: 200px auto 200px; grid-template-rows: 200px; }</style>猛虎分享

一起進(jìn)步

共勉







趣玩前端做最專業(yè)最懂你的前端開(kāi)發(fā)平臺(tái),提供你最需要的開(kāi)發(fā)學(xué)習(xí)資源。我們專注于前端開(kāi)發(fā)技術(shù)(html,css,js,jq,h5,css3)的學(xué)習(xí)與交流,我們堅(jiān)持,每天進(jìn)步一小步,人生進(jìn)步一大步!關(guān)注我們,與我們一起學(xué)習(xí)進(jìn)步。



關(guān)鍵詞:布局,方案,響應(yīng)

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉