作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前很难让网站的页脚正常工作。我认为这是因为我固定定位的标题和容器 div,但我需要将它们固定在滚动时保持在顶部。当容器 div 为空时,我不确定如何将页脚显示在底部。
HTML:-
<body>
<div id="wrapper">
<div id="header">
<div id="headerContent">
</div>
</div>
<script>
$(document).ready(function() {
$('#container').css('marginTop', $('#header').outerHeight(true) + $('#navbar').outerHeight(true) );
});
</script>
<div id="navbar">
<div id ="navbarContent">
</div>
</div>
<div id="container">
</div>
<div id="footer">
<div id="footerContent">
</div>
</div>
</div>
</body>
</html>
CSS:-
#container{
width:960px;
margin:auto;
overflow:hidden;
}
#wrapper{
min-height:100%;
position:relative;
}
#navbar{
width:100%;
height:40px;
margin:auto;
background-color:#4e8885;
position:fixed;
top:120px;
padding:0px;
}
#header{
width:100%;
height:120px;
margin:auto;
background-color:#8bbcba;
position:fixed;
top:0px;
}
#footer{
width:100%;
min-height:20px;
margin:auto;
background-color:#8bbcba;
position:absolute;
bottom:0;
left:0;
}
最佳答案
在您使用固定高度的示例中,没有必要动态计算边距。您应该能够设置 container
的边距以分别匹配 margin-top
和 margin-bottom
的页眉和页脚的总数.看到这个 jsFiddle:http://jsfiddle.net/9Jdrr/
如果需要动态计算的话,按照这个安排应该就可以了。
关于javascript - 固定 div 下的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15745322/
我是一名优秀的程序员,十分优秀!