[英]Div 100% Min Height Problems
當頁面包含大量內容時,將頁腳向下推,並且頁面以頁腳很好地結束。 但是,如果頁面中的內容較少,則頁腳會緊貼內容的底部,並在頁面的中部向下浮動,從而在頁面下方留出空間。
抱歉,已經討論了很多次了,盡管嘗試了許多解決方案,但我仍然遇到問題。 另外,我是新手。 我可以將頁腳停在底部,但有時它會覆蓋內容/在其下方留一個間隙/在調整窗口大小時會覆蓋內容/或者最小高度大於窗口的大小,並顯示滾動條。
請幫忙。
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0px;
padding: 0px;
border: 0px;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
:focus {
outline: none;
}
table {
border-collapse: separate;
border-spacing: 0px;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
table, td, th {
vertical-align: middle;
}
blockquote:before, blockquote:after, q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}
a img {
border: none;
}
.container {
width: 980px;
margin: 0 auto;
background: #fff;
z-index: 0;
position: relative;
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
-moz-box-shadow: 0 0 20px rgba(0, 0, 0, 0.25);
-webkit-box-shadow: 0 0 20px rgba(0, 0, 0, 0.25);
box-shadow: 0 0 20px rgba(0, 0, 0, 0.25);
}
.hfeed {
width: 700px;
float: right;
margin: 0;
}
.aside {
width: 220px;
float: left;
margin: 0 0 0 20px;
}
.aside ul {
margin: 0;
padding: 0;
list-style: none;
}
.footer {
clear: both
}
body, input, textarea {
font: 12px/18px Arial, sans-serif;
color: #666;
}
body {
background: #eee;
min-width: 980px;
}
#content {
padding: 0 0 15px 0;
background-image: none;
z-index: 0;
position: relative;
}
#inner_content {
padding: 0 15px 0 0;
margin: 0;
}
#full_width {
padding: 0 0 0 20px;
width: 940px;
}
#full_width h1 {
margin: 0 0 20px 0
}
.footer {
width: 100%;
padding-bottom: 0px;
position: relative;
background: #333 url(./_assets/img/bg-footer.png) left top repeat-x;
border-top: 0px solid rgba(50, 50, 50, 0.1);
}
.footer-info {
background: none;
margin: 0px auto 0px auto;
padding: 25px 20px 0px 20px;
width: 940px;
color: #aaa;
z-index: -1;
}
.footer-info .latest, .footer-info .offers {
margin-right: 20px
}
.footer-info .block ul li a:hover {
color: #ccc
}
.footer-info .featured a.ad-125 {
margin: 20px 5px 0 5px;
display: block;
float: left;
width: 133px;
height: 133px;
overflow: hidden;
}
.footer-info .featured img {
padding: 3px;
background: #444;
border: 1px solid #555;
}
.footer-info .featured img:hover {
background: #555;
border: 1px solid #666;
}
.footer-info .featured p {
text-align: right;
clear: both;
padding: 5px 10px 0 0;
margin: 0;
}
.footer-info .featured p a {
font-size: 12px;
color: #666;
background: url(_assets/img/bg-link.jpg) left 1px no-repeat;
padding-left: 17px;
}
.footer-info .featured p a:hover {
background-position: left -12px;
text-decoration: none;
color: #31cef5;
}
.footer-base {
width: 100%;
height: 30px;
background: #111;
margin: 0 auto 0px auto;
padding: 0px;
z-index: 1;
position: relative;
border-top: 1px solid #333;
}
.footer-base-inner {
width: 940px;
margin: 0 auto;
}
.footer-base p {
font-size: 10px;
margin: 0 !important;
padding: 0;
border-right: none;
line-height: 30px;
text-align: center;
}
.footer-base p a {
text-decoration: underline;
color: #666;
}
.footer-base p a:hover {
text-decoration: none
}
.textwidget {
font-size: 11px;
margin-bottom: 20px;
}
.footer .menu {
position: relative;
top: 0;
}
.footer .menu li {
float: none;
}
.footer .menu li a {
text-shadow: none;
font-weight: normal;
line-height: 23px;
color: #999;
font-weight: inherit;
}
.footer .menu li a:hover {
text-shadow: none
}
對於頁腳,我使用一個簡單的解決方案:
假設我們有這樣的布局:
<div class="content">
<p>All your page elements would go there</p>
</div>
<footer>
<p>Your Footer</p>
</footer>
一個簡單有效的解決方案是:
.content {
min-height: 100vh; // vh is the vertical height of the browser viewport
}
這樣,除非內容大於瀏覽器的視口,否則我們將確保頁腳始終不可見且位於頁面底部。
缺點:
您可以使用此技巧將頁腳始終放在頁面底部。 如果內容簡短,則它將位於屏幕底部。 如果內容很長,則頁腳將在內容之后。 它很簡單,可以在每種瀏覽器中使用。
HTML:
<div id="container">
// ALL THE PAGE HTML GOES IN HERE
<div id="push"></div>
</div><!—End Container—>
<div id="footer">// FOOTER HERE</div>
CSS:
#container {
min-height: 100%;
margin-bottom: -330px;
position: relative;
}
#footer {
height: 330px;
position: relative;
}
#push {
height: 330px;
clear: both;
}
基本上,您獲得footer
的height
,並將相同的height
#push
。 然后將負margin-bottom
添加到container
div,再次設置為height
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.