2012-10-10 74 views
0

我一直在搞CSS,但我仍然無法獲得「粘腳」,因爲某些原因工作。強制頁腳留在底部CSS

如果沒有足夠的內容,頁腳正常工作,並停留在底部,但是,如果有很多內容,最後100px總是在頁腳後面,當它不應該是,我不知道爲什麼。

要看看會發生什麼,請訪問:http://hevvo.eu/~dev/backtrack/index.php

任何幫助將不勝感激。

+0

這看起來很好,我有什麼問題?並且僅在某些瀏覽器中使用?看起來很不錯Firefox 15.0.1 – thatidiotguy

+0

我使用的是Firefox,我也使用過Chrome,但它在那裏也不起作用。 – Karl

回答

1

有很多關於這個的文章。我最喜歡的一個是:

http://www.cssstickyfooter.com/using-sticky-footer-code.html

+0

事實上,這就是我使用的;)但它仍然無法正常工作 – Karl

+0

它只適用於內容很少時,一旦有一整頁的內容,它隱藏在頁腳後面,而不是將頁腳推到最後100px左右。 – Karl

+0

只需將** padding-bottom:100px; **添加到#wrapper元素即可。 –

2

從CSS-招數:http://css-tricks.com/snippets/css/sticky-footer/

CSS:

* { margin:0; padding:0; } 

html, body, #wrap { height: 100%; } 

body > #wrap {height: auto; min-height: 100%;} 

#main { padding-bottom: 150px; } /* must be same height as the footer */ 

#footer { 
    position: relative; 
    margin-top: -150px; /* negative value of footer height */ 
    height: 150px; 
    clear:both; 
} 

/* CLEAR FIX*/ 
.clearfix:after { 
    content: "."; 
    display: block; 
    height: 0; 
    clear: both; 
    visibility: hidden; 
} 
.clearfix { 
    display: inline-block; 
} 
/* Hides from IE-mac \*/ 
* html .clearfix { height: 1%;} 
.clearfix { display: block;} 
/* End hide from IE-mac */ 

HTML:

<div id="wrap"> 

    <div id="main" class="clearfix"> 

    </div> 

</div> 

<div id="footer"> 

</div> 
+0

在我看來,這是很多不必要的額外CSS。 – BentOnCoding

+0

的確如此,但是當你處理跨瀏覽器一致性和表示時,CSS總是膨脹。 – jrd1

0

你忘了對.wrapper設置padding-bottom: (height-of-footer)px。一旦你確定了,它就可以正常工作。即:

.wrapper { 
    min-height: 100%; 
    background: #F7F4EB; 
    padding-bottom: 100px; 
} 
+0

不,我沒有這麼做,因爲當填充被設置並且內容很少時,填充是可見的並且看起來很荒謬,當它還有很多內容時它也不能解決它。 – Karl

+0

很多的內容:http://hevvo.eu/~dev/backtrack/index1.php – Karl

+0

沒有內容:http://hevvo.eu/~dev/backtrack/index.php – Karl

0

通過在內容周圍添加一個新的div並添加一個填充底部:100px;到它。