CSS頁面底部固定的6種方法

2021-10-09 12:58:26 字數 1049 閱讀 7057

方法 一、 footer高度固定+絕對定位

="w"

>

="head"

>

<

/div>

="content"

>

<

/div>

="foot"

>

<

/div>

<

/div>

.w.head

.content

.foot

方法

二、在主體content 上的下邊距增加乙個負值等於底部高度

>

headerheader

>

>

contentmain

>

>

footerfooter

>

html,body

main

header,

footer

方法

三、通過設定flexbox ,將主體margin設定為 flex

header<

/header>

content<

/main>

footer<

/footer>

body

main

方法四:通過函式calc()計算內容的高度

header<

/header>

content<

/main>

footer<

/footer>

main

方法五:通過設定flex,將footer的margin-top設定為auto

header<

/header>

content<

/main>

footer<

/footer>

body

header,footer

footer

CSS粘住固定底部的5種方法

本文主要介紹乙個footer元素如何粘住底部,使其無論內容多或者少,footer元素始終緊靠在瀏覽器的底部。我們知道,當內容足夠多可以撐開底部到達瀏覽器的底部,如果內容不夠多,不足以撐開元素到達瀏覽器的底部時,下面要講的布局就是解決如何使元素粘住瀏覽器底部。需求看下圖 有乙個全域性的元素包含除了底部...

footer固定在頁面底部的幾種方法

body header header header main content main footer footer footer body html body header main main的padding bottom值要等於或大於footer的height值 footer 首先,設定body的...

CSS實現footer固定在頁面底部

作為乙個頁面仔你一定遇到過 當乙個html頁面中含有較少的內容時,web頁面的 footer 部分隨著飄上來,處在頁面的半腰中間,給視覺效果帶來極大的影響,讓你的頁面看上去很不好看,特別是現在寬屏越來越多,這種現象更是常見。那麼如何將web頁面的 footer 部分永遠固定在頁面的底部呢?先來看下下...