【发布时间】:2016-05-09 14:09:22
【问题描述】:
在下面的代码中,我遇到了一些奇怪的问题。
1) mainContainer div 下方有一个 11 像素高的黑条,它不会消失。即使将 body 元素的绝对位置设置为 top、left、right、bottom 时也是如此。这会无缘无故地导致滚动条。
2) 页脚应始终贴在底部,但绝不应与mainBody div 重叠。为了实现这一点,我给了它一个绝对位置,并使其成为具有相对位置的mainContainer div 的子项。但它仍然会覆盖mainBody div 到一定高度。
一段时间以来,我一直在尝试自己解决这些问题,但我就是想不通。所以现在我希望你们能帮助我。
html {
height: 100%;
}
body {
height: 100%;
padding: 0;
margin: 0;
}
@font-face {
font-family:"Glass Antiqua";
src: url("GlassAntiqua-Regular.ttf");
}
body {
font-family: Glass Antiqua;
color: White;
font-size: 50px;
background-color: black;
}
header #logo h1 {
margin-top: 10px;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
width: calc(100% - 40px);
margin-top: 0;
background: #234e60;
background: linear-gradient(top, #234e60 0%, #245163 100%);
background: -moz-linear-gradient(top, #234e60 0%, #245163 100%);
background: -webkit-linear-gradient(top, #234e60 0%,#245163 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
list-style: none;
position: relative;
display: inline-table;
font-size: 20px;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li:first-child {
margin-left: 8px;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #193e4e;
background: linear-gradient(top, #193e4e 0%, #1a4050 40%);
background: -moz-linear-gradient(top, #193e4e 0%, #1a4050 40%);
background: -webkit-linear-gradient(top, #193e4e 0%,#1a4050 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 25px 35px;
color: #fff; text-decoration: none;
}
footer {
bottom: 0;
height: 150px;
position: absolute;
}
#mainContainer {
margin: auto;
padding-left: 25px;
padding-right: 25px;
width: 830px;
min-height: 100%;
background: #377a96;
position: relative;
}
#logo {
background: url(http://www.icecub.nl/images/banner_bats.png);
height: 130px;
margin-top: 0px;
border: 1px solid black;
text-align: center;
}
#hr_lines {
width: 100%;
height: 3px;
background: white;
position: relative;
}
#hr_blue {
width: 100%;
height: 1px;
position: absolute;
top: 1px;
background: #234e60;
}
#mainBody {
height: 500px;
border: 1px solid red;
}
#img_footer {
width: 830px;
height: 150px;
}
<div id="mainContainer">
<header>
<div id="logo">
<h1>Welcome</h1>
</div>
<div id="hr_lines">
<div id="hr_blue"></div>
</div>
<nav>
<ul>
<li><a href="home.html">Home</a><li>
<li><a href="introductie.html">Introductie</a></li>
<li><a href="opleiding.html">Mijn Opleiding</a></li>
<li><a href="werk.html">Eigen Werk</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
<div id="mainBody"></div>
<footer>
<img src="http://www.icecub.nl/images/boo.png" id="img_footer" alt="Afsluiting" />
</footer>
</div>
【问题讨论】:
-
我设法通过从您的
#mainContainerdiv 中删除position: relative来修复它... -
@Joum 如果我删除它,它将允许页脚完全覆盖主体。只需尝试将浏览器大小调整为更小的尺寸,您就会明白我的意思
-
是的,我已经看到了...其他人的答案可能涵盖了您的问题,但是如果您不介意,我想向您指出 getbootstrap.com 的方向。 . 在我看来,你想做的很多事情已经被他们很好地覆盖了......