国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

詳解CSS五種方式實(shí)現(xiàn)Footer置底

2024-07-11 08:32:17
字體:
供稿:網(wǎng)友

頁腳置底(Sticky footer)就是讓網(wǎng)頁的footer部分始終在瀏覽器窗口的底部。

當(dāng)網(wǎng)頁內(nèi)容足夠長以至超出瀏覽器可視高度時(shí),頁腳會(huì)隨著內(nèi)容被推到網(wǎng)頁底部;但如果網(wǎng)頁內(nèi)容不夠長,置底的頁腳就會(huì)保持在瀏覽器窗口底部。

方法一:將內(nèi)容部分的margin-bottom設(shè)為負(fù)數(shù)

<div class="wrapper"> <!-- content --> <div class="push"></div></div><div class="footer">footer</div>
html, body { margin: 0; padding: 0; height: 100%;}.wrapper { min-height: 100%; margin-bottom: -50px; /* 等于footer的高度 */}.footer, .push { height: 50px;}

1、這個(gè)方法需要容器里有額外的占位元素(div.push)。

2、div.wrapper的margin-bottom需要和div.footer的-height值一樣,注意是負(fù)height。

方法二:將頁腳的margin-top設(shè)為負(fù)數(shù)

給內(nèi)容外增加父元素,并讓內(nèi)容部分的padding-bottom與頁腳的height相等。

<div class="content"> <div class="content-inside"> <!-- content --> </div></div><div class="footer">footer</div>
html, body { margin: 0; padding: 0; height: 100%;}.content { min-height: 100%;}.content-inside { padding: 20px; padding-bottom: 50px;}.footer { height: 50px; margin-top: -50px;}

方法三:使用calc()設(shè)置內(nèi)容高度

<div class="content"> <!-- content --></div><div class="footer">footer</div>
.content { min-height: calc(100vh - 70px);}.footer { height: 50px;}

這里假設(shè)div.content和div.footer之間有20px的間距,所以70px=50px+20px

方法四:使用flexbox彈性盒布局

以上三種方法的footer高度都是固定的,如果footer的內(nèi)容太多則可能會(huì)破壞布局。

<div class="content"> <!-- content --></div><div class="footer">footer</div>
html { height: 100%;}body { min-height: 100%; display: flex; flex-direction: column;}.content { flex: 1;}

方法五:使用Grid網(wǎng)格布局

<div class="content"> <!-- content --></div><div class="footer">footer</div>
html { height: 100%;}body { min-height: 100%; display: grid; grid-template-rows: 1fr auto;}.footer { grid-row-start: 2; grid-row-end: 3;}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯(cuò)新站長站。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 安远县| 合肥市| 甘谷县| 海伦市| 阳信县| 平乡县| 阜平县| 孟津县| 兖州市| 尉犁县| 伊金霍洛旗| 宾川县| 巩义市| 自贡市| 南漳县| 宁晋县| 大田县| 兖州市| 正蓝旗| 安国市| 淳化县| 忻城县| 雅江县| 开平市| 建湖县| 昂仁县| 华安县| 大姚县| 昆山市| 剑阁县| 灵台县| 平和县| 济阳县| 岗巴县| 瑞丽市| 连平县| 丰顺县| 六安市| 娱乐| 浪卡子县| 神农架林区|