2010-04-14 83 views
4

在這種情況下,我爲此Web應用程序開發了一個CSS代碼..並且有時生成的數據太小,頁腳的網站出現在頁面中間,看起來很奇怪。如何讓短內容頁面到達瀏覽器窗口底部,然後出現頁腳

我想將背景的空白部分推到瀏覽器底部,然後是頁腳。如果頁面很長,那麼文本不會被頁腳重疊。

有人能幫我解決這個代碼嗎?

我一直在嘗試用一些我這個網頁上找到的代碼:http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page其中談到了幾乎同樣的問題,但我不能把它完全做到:
我在做什麼錯?

@charset "utf-8"; 
body { 
    margin: 0; 
    padding: 0; 
    text-align: center; 
    height:100%; 
    position: relative; 
    height:100%; /* needed for container min-height */ 
    } 
.spacer { 
    clear: both; 
    height: 0; 
    margin: 0; 
    padding: 0; 
    font-size: 0.1em; 
} 
.spacer_left { 
    clear: left; 
    margin: 0 0 10px 0; 
    padding: 0; 
    font-size: 0.1em; 
} 
hr { 
    height: 1px; 
    margin: 20px 0 20px 0; 
    border: 0; 
    color: #ccc; 
    background: #ccc; 
} 
#container { 
    position:relative; /* needed for footer positioning*/ 
    height:auto !important; /* real browsers */ 
    height:100%; /* IE6: treaded as min-height*/ 
    min-height:100%; /* real browsers */ 

    width: 1160px; /* width of the site ! */ 
    margin: 0 auto; 
    padding: 0; 
    border: 1px solid #333; 
    text-align: left; 
} 
/* Context Bar */ 
h1#contexto { 
    background:url('../images/menubarbg2.png'); 
    width:1160px; 
    height:30px; 
    position:relative; 
    margin-top:10px; 
    visibility: inherit; 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:12px; 
} 
#header { 
    margin: 0; 
    padding: 5px; 
    height:70px; 
} 
h1#titulo { 
    margin: 0; 
    padding: 0 0 0; 

} 
#content { 

margin: -15px 20px 0 20px; 
/*padding: -6px 5px 20px 5px;*/ 
padding:1em 1em 5em; /* bottom padding for footer */ 

} 
div#content.columns { 
    margin-left: 100px; 
} 
#content abbr, #content acronym { 
    cursor: help; 
    border-bottom: 1px dotted; 
} 
#content ul { 
    list-style-type: square; 
} 
#content ul li, #content ol li { 
    margin: 0 0 0.4em 0; 
    padding: 0; 
} 
#content blockquote { 
    width: 75%; 
    margin: 0 auto; 
    padding: 20px; 
} 

#footer 
{ 
margin: 0; 
height: -30px; 
padding: 5px; 
clear: both; 
bottom:0; 
position:relative; 
} 

UPDATE:解決方案

@charset "utf-8"; 
body, html { 
    margin: 0; 
    padding: 0; 
    text-align: center; 
    position: relative; 
    height:100%; /* needed for footer positioning*/ 
} 
.spacer { 
    clear: both; 
    height: 0; 
    margin: 0; 
    padding: 0; 
    font-size: 0.1em; 
} 
.spacer_left { 
    clear: left; 
    margin: 0 0 10px 0; 
    padding: 0; 
    font-size: 0.1em; 
} 
hr { 
    height: 1px; 
    margin: 20px 0 20px 0; 
    border: 0; 
    color: #ccc; 
    background: #ccc; 
} 
#container { 
    position:relative; /* needed for footer positioning*/ 
    min-height: 100%;/* needed for footer positioning*/ 
    height: auto !important;/* needed for footer positioning*/ 
    height: 100%;/* needed for footer positioning*/ 
    margin: 0 auto -30px;/* needed for footer positioning*/ 
    width: 1160px; 
    padding: 0; 
    border: 1px solid #333; 
    text-align: left; 
} 
#header { 
    margin: 0; 
    padding: 5px; 
    height:70px; 
} 
h1#titulo { 
    margin: 0; 
    padding: 0 0 0; 
} 
h1#contexto { 
    background:url('../images/menubarbg2.png'); 
    width:1160px; 
    height:30px; 
    position:relative; 
    margin-top:10px; 
    visibility: inherit; 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:12px; 
} 
#content { 
    margin: -15px 20px 30px 20px; /* needed for footer positioning*/ 
} 
div#content.columns { 
    margin-left: 100px; 
} 
#content abbr, #content acronym { 
    cursor: help; 
    border-bottom: 1px dotted; 
} 
#content ul { 
    list-style-type: square; 
} 
#content ul li, #content ol li { 
    margin: 0 0 0.4em 0; 
    padding: 0; 
} 
#content blockquote { 
    width: 75%; 
    margin: 0 auto; 
    padding: 20px; 
} 
#footer, .push /* needed for footer positioning*/ { 
    padding: 5px; 
    clear: both; 
    position:absolute;/* needed for footer positioning*/ 
    bottom:0;/* needed for footer positioning*/ 
    height: -30px;/* needed for footer positioning*/ 
    width:1150px; 
} 
+0

請仔細閱讀在這個非常職位的更新。代碼的修正已經完成,它的工作原理,所以我在這裏發佈,以防萬一任何人想看到舊的CSS和修復之間的區別。 感謝用戶Yongho和Ricebowl的幫助。 – UXdesigner 2010-04-14 15:37:32

回答

1

您可以通過具有車身高度等於瀏覽器窗口的高度獲得了「粘頁腳」(即:設置高度爲100 %),然後強制頁腳位於瀏覽器窗口的任何高度的底部。

CSS:

body { 
    height: 100%; 
    position: relative; 
} 

#footer { 
position:absolute; 
bottom:0; 
height:60px; 
background:#ccc; 
} 

HTML:

<html><body> 

text here text here 

<div id="footer"> 
    Im in the footer and bottom of the page! 
</div> 

</body></html> 
+0

嗯,我不知道如何。但我只是編輯了一下我的代碼,它的工作,與您的建議。看起來這是我之前做的同樣的事情,但由於某種原因沒有奏效。感謝您的熱心幫助。不勝感激。 – UXdesigner 2010-04-14 14:56:17

+1

我有一段時間沒有嘗試過thiS方法,但是從內存中 - 它可能是一個文檔類型的問題 - 我似乎記得這導致頁腳始終在屏幕上,但也重疊溢出的內容滾動時瀏覽器的下邊框。雖然我不是低調投票,因爲我無法確定。 – 2010-04-14 15:07:56

+0

我猜,你可以解決身體上填充底部的重疊問題。但是,您希望將頁腳壓低到內容的底部,在滾動條的下方......我對如何獲得該信息沒有信心,但也許使用最小高度而非高度。 – ANeves 2010-04-14 15:54:50

相關問題