我使用my site在this method设置了粘性页脚,由于某种原因,内容底部和页脚顶部之间存在大量额外空间。我无法弄清楚为什么。由于第一页上的内容不多,因此页面甚至不应超出视口范围,也不应该有滚动条。发生了什么事?
以下是该页面的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" type="text/css" href="/css/styles.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/pygment_trac.css" media="screen" />
<link href="/menu_assets/styles.css" rel="stylesheet" type="text/css">
<title>gulshansingh.com</title>
</head>
<body>
<header>
<img src="/images/banner.jpg">
</header>
<div id='cssmenu'>
<ul>
<li><a href='/'><span>Home</span></a></li>
<li><a href='/about/'><span>About</span></a></li>
<li><a href='/projects/'><span>Projects</span></a></li>
<li><a href='/articles/'><span>Articles</span></a></li>
</ul>
</div>
<div class="container">
<section id="main_content">
<h3>Welcome to GitHub Pages.</h3>
<p>This is a test home page for my site</p>
<pre><code>$ cd your_repo_root/repo_name
$ git fetch origin
$ git checkout gh-pages
</code></pre>
<h3>Section 2</h3>
<p>Lorem ipsum</p>
</section>
<div class="push">
</div>
</div>
<div id="footer">
Footer content goes here
</div>
</body>
</html>
这是CSS(尽管查看Firebug / CDT可能会更有帮助):
* {
margin: 0;
}
html, body {
height: 100%;
min-height: 100%;
}
.container {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -80px; /* the bottom margin is the negative value of the footer's height */
}
#footer, .push {
height: 80px; /* .push must be the same height as .footer */
}
body {
margin: 0;
padding: 0;
background: #161616;
color: #eaeaea;
font: 16px;
line-height: 1.5;
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
}
/* General & 'Reset' Stuff */
.container {
width: 100%;
}
section {
display: block;
margin: 0 0 20px 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 15px 0 5px;
}
p {
margin: 0 0 5px;
}
li {
line-height: 1.4 ;
}
header, header img {
position: relative;
z-index: 10;
width: 100%;
height: 150px;
box-shadow: 0 0 5px #469B46;
-webkit-box-shadow: 0 0 5px #469B46;
-moz-box-shadow: 0 0 5px #469B46;
-o-box-shadow: 0 0 5px #469B46;
-ms-box-shadow: 0 0 5px #469B46;
}
#downloads .btn {
display: inline-block;
text-align: center;
margin: 0;
}
/* Main Content
*/
#main_content {
padding: 20px;
background: #474747;
width: 80%;
margin: 50px auto;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-webkit-font-smoothing: antialiased;
}
section img {
max-width: 100%
}
h1, h1 a, h2, h2 a, h3, h3 a, h4, h4 a, h5, h5 a, h6, h6 a {
font-weight: normal;
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
color: #b5e853;
letter-spacing: -0.03em;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1),
0 0 5px rgba(181, 232, 83, 0.1),
0 0 10px rgba(181, 232, 83, 0.1);
-moz-transition: all 0.3s ease-out; /* FF3.7+ */
-o-transition: all 0.3s ease-out; /* Opera 10.5 */
-webkit-transition: all 0.3s ease-out; /* Saf3.2+, Chrome */
transition: all 0.3s ease-out;
}
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover {
color: #ccc;
}
#main_content h1 {
font-size: 30px;
}
#main_content h2 {
font-size: 24px;
}
#main_content h3 {
font-size: 18px;
}
#main_content h4 {
font-size: 14px;
}
#main_content h5 {
font-size: 12px;
text-transform: uppercase;
margin: 0 0 5px 0;
}
#main_content h6 {
font-size: 12px;
text-transform: uppercase;
color: #999;
margin: 0 0 5px 0;
}
dt {
font-style: italic;
font-weight: bold;
}
/*
ul li {
list-style: none;
}
ul li:before {
content: ">>";
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
font-size: 13px;
color: #b5e853;
margin-left: -37px;
margin-right: 21px;
line-height: 16px;
}*/
blockquote {
color: #aaa;
padding-left: 10px;
border-left: 1px dotted #666;
}
pre {
background: rgba(0, 0, 0, 0.9);
border: 1px solid rgba(255, 255, 255, 0.15);
padding: 10px;
font-size: 14px;
color: #b5e853;
border-radius: 2px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
text-wrap: normal;
overflow: auto;
overflow-y: hidden;
}
table {
width: 100%;
margin: 0 0 20px 0;
}
th {
text-align: left;
border-bottom: 1px dashed #b5e853;
padding: 5px 10px;
}
td {
padding: 5px 10px;
}
hr {
height: 0;
border: 0;
border-bottom: 1px dashed #b5e853;
color: #b5e853;
}
/* Buttons
*/
.btn {
display: inline-block;
background: -webkit-linear-gradient(top, rgba(40, 40, 40, 0.3), rgba(35, 35, 35, 0.3) 50%, rgba(10, 10, 10, 0.3) 50%, rgba(0, 0, 0, 0.3));
padding: 8px 18px;
border-radius: 50px;
border: 2px solid rgba(0, 0, 0, 0.7);
border-bottom: 2px solid rgba(0, 0, 0, 0.7);
border-top: 2px solid rgba(0, 0, 0, 1);
color: rgba(255, 255, 255, 0.8);
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
text-decoration: none;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.75);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.btn:hover {
background: -webkit-linear-gradient(top, rgba(40, 40, 40, 0.6), rgba(35, 35, 35, 0.6) 50%, rgba(10, 10, 10, 0.8) 50%, rgba(0, 0, 0, 0.8));
}
.btn .icon {
display: inline-block;
width: 16px;
height: 16px;
margin: 1px 8px 0 0;
float: left;
}
.btn-github .icon {
opacity: 0.6;
background: url("../images/blacktocat.png") 0 0 no-repeat;
}
/* Links
a, a:hover, a:visited
*/
a {
color: #63c0f5;
text-shadow: 0 0 5px rgba(104, 182, 255, 0.5);
}
/* Clearfix */
.cf:before, .cf:after {
content:"";
display:table;
}
.cf:after {
clear:both;
}
.cf {
zoom:1;
}
#footer {
border-top: 2px solid #15893d;
text-align: center;
width: 100%;
height: 80px;
background: #0c0c0c;
line-height: 80px;
}
#footer_inner {
display: table-cell;
}
#footer a {
text-decoration: none;
color: #eaeaea;
}
#footer a:hover {
text-decoration: underline;
color: #eaeaea;
}
答案 0 :(得分:1)
.container
元素应该包围除页脚之外的所有其他元素。这意味着你必须将标题放在.container
元素中,因为它的高度为100%意味着它将占用视口的高度。由于您的标题/导航已从.container
元素中排除,因此视口高度将进一步向下延伸到标题的高度。
请考虑将您的示例发布在一个小提琴而不是您的网站,或任何其他外部网站,使其过于本地化,与SO社区的其他成员不太相关。