HTML將footer置底的方法(使用CSS)

HTML將footer置底的方法(使用CSS) - Web Development Notes

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="2.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="id_wrapper">
    <div id="id_header">
        Header Block
    </div>
    <div id="id_content">
        Content Block<br>
        Content Block<br>
        Content Block<br>
        Content Block<br>
        Content Block<br>
        Content Block<br>
        Content Block<br>
        Content Block<br>
        <!--隨內(nèi)容增多,自動增長-->
    </div>
    <footer id="id_footer">
        Footer Block
    </footer>
</div>
</body>
</html>

css

* {
    margin: 0;
}

html, body {
    /* 設(shè)定body高度為100% 拉到視窗可視的大小 */
    height: 100%;
}

#id_wrapper {
    /*設(shè)定高度最小為100%, 如果內(nèi)容區(qū)塊很多, 可以長大!*/
    min-height: 100%;
    position: relative; /*位置relative, 作為footer位置的參考*/
    text-align: center;
}

#id_header {
    height: 40px;
    line-height: 40px;
    background-color: red;
}

#id_content {
    /* 留出header及footer區(qū)塊的空間*/
    padding-top: 40px;
    padding-bottom: 40px;
    background-color: #2aabd2;
}

#id_footer {
    height: 40px; /*設(shè)定footer高度*/
    position: absolute; /*設(shè)定footer絕對位置在底部*/
    bottom: 0;
    width: 100%; /*展開footer寬度*/
    background-color: yellow;
    line-height: 40px;
}

效果

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標(biāo)準(zhǔn)。 注意:講述HT...
    kismetajun閱讀 28,824評論 1 45
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 14,162評論 1 92
  • 1、通過CocoaPods安裝項目名稱項目信息 AFNetworking網(wǎng)絡(luò)請求組件 FMDB本地數(shù)據(jù)庫組件 SD...
    陽明AI閱讀 16,210評論 3 119
  • 一個人的氣質(zhì)沒有辦法復(fù)制,所經(jīng)歷的,所懂得的不盡相同。你可以有美的五官,傲人的身材,可是你卻不能平白無故的就擁有傲...
    艾艾子閱讀 370評論 0 0
  • 江南好,能不憶江南 離別已離別 過去已過去 心底留下一份美好甜蜜 江南好,能不憶江南
    胡子長閱讀 291評論 0 0

友情鏈接更多精彩內(nèi)容