内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

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

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

成都創(chuàng)新互聯(lián)公司專注于辰溪網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎ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,當頁面主題內容不夠長時,footer定位在窗口的底部,當頁面主題內容超出窗口后,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)了的哦?。。?!

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

營銷型網(wǎng)站建設
江山市| 长垣县| 深泽县| 巫溪县| 扶余县| 璧山县| 江源县| 襄垣县| 三明市| 西畴县| 龙山县| 邵阳县| 甘洛县| 尚志市| 高淳县| 怀远县| 夏邑县| 贵港市| 镇宁| 公主岭市| 清原| 积石山| 阿尔山市| 彰化县| 南宫市| 吴堡县| 香港| 天等县| 万宁市| 长宁县| 岑巩县| 新化县| 乳源| 东兴市| 香格里拉县| 东海县| 于田县| 华安县| 平遥县| 德清县| 德令哈市|