網頁中的foot底部定位問題

來源:互聯網
上載者:User

標籤:

有時候,我們會碰到這樣一個問題。
網頁底部一般有個foot對吧,放置一些友情連結著作權聲明什麼的,這個模組是如何定位的?
要是直接放內容地區的下面的話,假如是內容地區的高度不夠的話,那麼foot下面是會留有很多空白的;
好了,這時你會說直接相對body定位到底部,那麼當內容地區的高度多的話或使用者把瀏覽器放小看的話,部分內容是會被遮住了的。
這裡我們可以有個方法解決這問題,通過::after虛擬元素撐起footer的高度,然後margin-bottom一個負值吃掉這個::after元素的高度。

html代碼:
<div class="wrap">
    <div>1這裡是內容地區</div>
    <div>2這裡是內容地區</div>
    <div>3這裡是內容地區</div>
    <div>4這裡是內容地區</div>
    <div>5這裡是內容地區</div>
</div>
<footer class="footer">友情連結and著作權聲明</footer>

 

CSS代碼:

html, body{height: 100%; font-size: 24px;}
.wrap{min-height: 100%; margin-bottom: -60px; background: green;}
.wrap:after{content: ""; display: block;}
.footer, .wrap:after{height: 60px;}
.footer{background: orange; text-align: center;}

網頁中的foot底部定位問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.