這篇文章給大家介紹利用CSS怎么將頁面底部固定,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
創新互聯建站主要從事網站制作、成都做網站、網頁設計、企業做網站、公司建網站等業務。立足成都服務豐鎮,10多年網站建設經驗,價格優惠、服務專業,歡迎來電咨詢建站服務:18982081108
css是一種用來表現HTML或XML等文件樣式的計算機語言,主要是用來設計網頁的樣式,使網頁更加美化。它也是一種定義樣式結構如字體、顏色、位置等的語言,并且css樣式可以直接存儲于HTML網頁或者單獨的樣式單文件中,而樣式規則的優先級由css根據這個層次結構決定,從而實現級聯效果,發展至今,css不僅能裝飾網頁,也可以配合各種腳本對于網頁進行格式化。
方法一:footer高度固定+絕對定位
html
<div class="dui-container"> <header>Header</header> <main>Content</main> <footer>Footer</footer> </div>
CSS
.dui-container{ position: relative; min-height: 100%; } main { padding-bottom: 100px; } header, footer{ line-height: 100px; height: 100px; } footer{ width: 100%; position: absolute; bottom: 0 }
查看效果
方法二:在主體content上的下邊距增加一個負值等于底部高度
html
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS
html, body { height: 100%; } main { min-height: 100%; padding-top: 100px; padding-bottom: 100px; margin-top: -100px; margin-bottom: -100px; } header, footer{ line-height: 100px; height: 100px; }
查看效果
方法三:將頁腳的margin-top設為負數
html
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS
main { min-height: 100%; padding-top: 100px; padding-bottom: 100px; } header, footer{ line-height: 100px; height: 100px; } header{ margin-bottom: -100px; } footer{ margin-top: -100px; }
查看效果
方法四: 通過設置flex,將footer的margin-top設置為auto
html
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS
body{ display: flex; min-height: 100vh; flex-direction: column; } header,footer{ line-height: 100px; height: 100px; } footer{ margin-top: auto; }
查看效果
方法五: 通過函數calc()計算內容的高度
html代碼
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS代碼
main{ min-height: calc(100vh - 200px); /* 這個200px是header和footer的高度 */ } header,footer{ height: 100px; line-height: 100px; }
查看效果
方法六: 通過設置flexbox,將主體main設置為flex
html
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS代碼
body{ display: flex; min-height: 100vh; flex-direction: column; } main{ flex: 1 }
查看效果
方法七: 使用grid布局
Html代碼
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS代碼
html { height: 100%; } body { min-height: 100%; display: grid; grid-template-rows: auto 1fr auto; } .footer { grid-row-start: 3; grid-row-end: 4; }
查看效果
方法八: display-*
html
<header>Header</header> <main>Content</main> <footer>Footer</footer>
CSS
body { min-height: 100%; display: table; width: 100%; } main { display: table-row; height: 100%; }
關于利用CSS怎么將頁面底部固定就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
當前標題:利用CSS怎么將頁面底部固定
新聞來源:http://www.yijiale78.com/article4/gsohie.html
成都網站建設公司_創新互聯,為您提供關鍵詞優化、網站營銷、網站建設、網站策劃、App設計、企業網站制作
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯