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

首頁 > 開發 > CSS > 正文

使用常見的sticky footer布局方式

2024-07-11 08:42:27
字體:
來源:轉載
供稿:網友

什么是sticky footer布局

我們常見的網站頁面都會把一個頁面分為:頭部區、內容區、頁腳區,當頭部區和內容區內容較少時,頁腳區能固定在網頁底部,而不是隨著文檔流排布。當頁面內容較多時,頁腳能隨著文檔內容自動撐開,顯示在頁面的最底部。這就是sticky footer布局。

實現方式

flex 實現

html代碼

<header class="header"></header>    <main class="content">        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>        <p>近段時間房管局四大金剛</p>    </main>    <footer class="footer"></footer>

css代碼

*{    margin: 0;    padding: 0;}html,body{    display: flex;    flex-direction: column;    min-height: 100%;    width: 100%;}.header{    background: gray;    height: 20px;}.content{    flex: 1;    overflow: auto;    background: greenyellow;}.footer{    background: pink;    height: 20px;}

flex布局方法簡單代碼少,因為pc端兼容性不是很好,可以廣泛用于移動端。

負margin布局方式

html代碼

<div class="wrapper clearfix">        <div class="title">            <h1>這里是頭部</h1>        </div>        <div class="main">            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>            <p>近段時間房管局四大金剛</p>        </div>    </div>    <div class="footer">        <p>© 2017 No rights reserved.</p>        <p>Made with ♥ by an anonymous pastafarian.</p>    </div>

css代碼

* {    margin: 0;    padding: 0;    text-align: center;}.wrapper {    min-height: 100%;    width: 100%;}.main {    margin-top: 64px;    padding-bottom: 64px;}.footer {    margin: -64px auto 0 auto;    background: orange;}.clearfix::after {    display: block;    content: ".";    height: 0;    clear: both;    visibility: hidden;}

這是兼容性最好的方案,各大瀏覽器都可兼容,就是需要提前知道footer的高度。且結構相對復雜。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 迁安市| 万安县| 连山| 湘潭县| 赣榆县| 北票市| 库尔勒市| 元江| 长沙县| 佛山市| 达孜县| 房产| 伊吾县| 白水县| 当雄县| 百色市| 卢氏县| 开鲁县| 岳池县| 天水市| 呼和浩特市| 红河县| 湘潭市| 贵德县| 四会市| 山阳县| 沁源县| 彰化县| 尤溪县| 丘北县| 贡嘎县| 莎车县| 五指山市| 扬中市| 凤山市| 泸州市| 吴旗县| 辽宁省| 习水县| 北辰区| 洞口县|