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

首頁(yè) > 開(kāi)發(fā) > CSS > 正文

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

2024-07-11 09:07:42
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

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

css,footer,footer固定在底部,絕對(duì)底部

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

<div class="wrapper">    <!-- content -->    <div class="push"></div></div><div class="footer">footer</div>
css/215829.html">css;">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。

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

給內(nèi)容外增加父元素,并讓內(nèi)容部分的padding-bottom與頁(yè)腳的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;}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到CSS教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遂溪县| 临湘市| 沅江市| 台安县| 阳江市| 安康市| 石楼县| 临夏市| 香港 | 弥渡县| 文化| 容城县| 柳州市| 全椒县| 三原县| 福建省| 泽州县| 巨野县| 荔浦县| 阳东县| 伊金霍洛旗| 比如县| 白河县| 呼和浩特市| 沅江市| 东乡县| 启东市| 长顺县| 昌邑市| 成武县| 格尔木市| 菏泽市| 修武县| 阿瓦提县| 霍州市| 宁武县| 邢台市| 乐至县| 奉新县| 西畴县| 九江县|