2014-04-05 182 views
0

我在我的網站上有不同的頁面大小在頁面底部設置頁腳

如何將頁腳始終設置在頁面底部?

請注意,我需要它在頁面的底部而不是在屏幕的底部,所以如果我有短的屏幕它將在底部,如果我有很長的時間,滾動頁面I只有當我向下滾動時纔會看到頁腳。

感謝

<footer> 
    <?PHP include "footer.php"; ?> 
</footer> 

CSS:

footer { 
    background: #294a2d; 
    width:100%; 
    height: 180px; 
    color: #fff; 
    margin-top: 50px; 
} 
+0

是'body'標籤的頁腳的孩子呢? –

+0

您使用的是php –

+0

@IPADDRESS - 是的 – user3396295

回答

1

您可以在body標籤這樣使用position:absolute;的頁腳和min-height

FIDDLE < - 幾乎沒有內容 FIDDLE < - 有很多的內容

HTML:

<div>... Content ...</div> 
<footer>... Footer ...</footer> 

CSS:

html{ 
    height:100%; 
    width:100%; 
    margin:0; 
} 
body { 
    width:100%; 
    min-height:100%; 
    margin:0; 
    position:relative; 
} 
div { 
    padding-bottom:100px; 
} 
footer { 
    position:absolute; 
    bottom:0; 
    width:100%; 
    height:100px; 
    background:gold; 
} 
+0

嗨。如果我用滾動頁面不好... – user3396295

+0

@ user3396295我不明白你的意思... –

+0

如果你有長頁面,用滾動,頁腳會出現在屏幕的底部,但不在底部的頁... – user3396295

0

你應該使用這個

footer { 
position : absolute ; 
bottom : 0 !important ; 
background: #294a2d; 
width:100%; 
height: 180px; 
color: #fff; 
margin-top: 50px; 
} 
+0

hi。如果我使用滾動頁面,則效果不佳 – user3396295

0

試試這個

html { 
    position: relative; 
    min-height: 100%; 
} 

body { 
    margin: 0 0 100px; /* bottom = footer height */ 
    padding: 25px; 
} 


footer { 
    background-color: green; 
    position: absolute; 
    left: 0; 
    bottom: 0; 
    height: 100px; 
    width: 100%; 
    overflow:hidden; 
} 

<footer> <h1>Footer Content</h1> </footer>