成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

CSS中怎么實現(xiàn)StickyFooter

這篇文章主要介紹了CSS中怎么實現(xiàn)Sticky Footer,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

成都創(chuàng)新互聯(lián)公司專注于辰溪網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供辰溪營銷型網(wǎng)站建設,辰溪網(wǎng)站制作、辰溪網(wǎng)頁設計、辰溪網(wǎng)站官網(wǎng)定制、微信小程序服務,打造辰溪網(wǎng)絡公司原創(chuàng)品牌,更為您提供辰溪網(wǎng)站排名全網(wǎng)營銷落地服務。

本文介紹了CSS Sticky Footer實現(xiàn)代碼,分享給大家,具體如下:

CSS中怎么實現(xiàn)Sticky Footer

上圖所顯示的效果就是sticky Footer,當頁面主題內(nèi)容不夠長時,footer定位在窗口的底部,當頁面主題內(nèi)容超出窗口后,footer顯示在頁面的最底部

以下給出幾種實現(xiàn)方案:

1. FlexBox布局

HTML結構如下:

<body>

    <div class="header">Sticky Footer</div>

    <div class="content">

        <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

    </div>

    <div class="footer">

        <p>This is footer</p>

    </div>

</body>

主要CSS如下:

body{

    display: flex;

    flex-flow: column;

    min-height: 100vh;

}

.content{

    flex: 1;

}

FlexBox實現(xiàn)就是這么簡單,實現(xiàn)效果也貼上來

CSS中怎么實現(xiàn)Sticky Footer CSS中怎么實現(xiàn)Sticky Footer CSS中怎么實現(xiàn)Sticky Footer

貼圖的效果好像不太好,但是效果是實現(xiàn)了的哦?。。。?/p>

2. 經(jīng)典套路:padding-bottom + margin-top

HTML結構如下:

<body>

    <div class="wrapper clearfix">

        <div class="title">Sticky Footer</div>

        <div class="content">

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        </div>

    </div>

    <div class="footer">

        <p>This is footer</p>

    </div>

</body>

主要CSS如下:

.wrapper{

    min-height: 100vh;

}

.content{

    padding-bottom: 50px;

}

.footer{

    height: 50px;

    margin-top: -50px;

}

實現(xiàn)效果(感覺需要裝個錄屏軟件了):

CSS中怎么實現(xiàn)Sticky Footer 

CSS中怎么實現(xiàn)Sticky Footer 

CSS中怎么實現(xiàn)Sticky Footer

使用此方案時要注意以下幾點:

1. wrapper的最小高度要等于窗口高度

2. content的padding-bottom、footer的margin-top和height這三個屬性值的絕對值需保持一致(因為margin-top為負值,所以說絕對值);保持一致的原因是更好的實現(xiàn)sticky footer,雖然height什么的偏小也能實現(xiàn)sticky footer效果,但是給最底部留下了空隙。

3. 這種方案的兼容性不錯,各大主流瀏覽器均可,emmmmm,還不錯

4. 當主體使用懸浮布局的時候,那么就需要考慮一個兼容性問題,這里使用的重點是為了Google chrome

上述第四條兼容性解決方案:

給.wrapper加上著名的clearfix hack:

.clearfix{

    display: inline-block

}

.clearfix:after{

    display: block

    content: "."

    height: 0

    line-height: 0

    clear: both

    visibility: hidden

}

3. 固定高度的解決方案

HTML結構如下:

<body>

    <div class="wrapper">

        <div class="header">Sticky Footer</div>

        <div class="content">

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

            <p>測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</p>

        </div>

    </div>

    <div class="footer">

        <p>This is footer</p>

    </div>

</body>

主要CSS樣式如下:

.wrapper{

    min-height: calc(100vh - 50px);

    box-sizing: border-box;

}

注:50px為footer的高度,calc()運算符前后都需要保留一個空格。

結果我就不貼了,大家自行腦補,跟上面的都差不多。。。

感謝你能夠認真閱讀完這篇文章,希望小編分享的“CSS中怎么實現(xiàn)Sticky Footer”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關知識等著你來學習!

文章標題:CSS中怎么實現(xiàn)StickyFooter
網(wǎng)址分享:http://jinyejixie.com/article24/pgsdje.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設計、網(wǎng)站維護、App開發(fā)、網(wǎng)頁設計公司、企業(yè)網(wǎng)站制作、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設
剑河县| 茂名市| 林西县| 泗水县| 海原县| 都昌县| 稻城县| 汶川县| 永福县| 阿城市| 江津市| 衡水市| 南丹县| 溧水县| 海阳市| 临城县| 芜湖县| 大渡口区| 来安县| 泸溪县| 沙雅县| 潞城市| 南川市| 鹤庆县| 西盟| 克拉玛依市| 黄平县| 大渡口区| 台江县| 永靖县| 井研县| 福鼎市| 阿拉善左旗| 铁力市| 宝鸡市| 荆门市| 游戏| 柳州市| 清原| 琼海市| 灵武市|