【发布时间】:2013-04-05 06:27:37
【问题描述】:
当我使用 relative 没有内容的位置时,页脚向上,absolute 有很多内容,页脚向下,并且 fixed它一直都在。
有没有一种简单的方法可以独立于内容到达页面末尾,随内容缩小和增长?
当内容多时,我们可以在首页看到页脚,当内容少时,我们会在底部看到。
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html,body {
padding: 0;
margin: 0;
}
header {
position:fixed;
top:0;
width:100%;
height:40px;
background-color:#333;
padding:20px;
}
footer {
background-color: #333;
width: 100%;
bottom: 0;
position: relative;
}
#main{
padding-top:100px;
text-align:center;
}
</style>
</head>
<body>
<header>
header
</header>
<div id="main">
main
</div>
<footer>
footer
</footer>
</body>
</html>
【问题讨论】:
-
在这里,我找到了一个很好的例子,但是添加了很多未使用的 css 代码。 twitter.github.io/bootstrap/examples/sticky-footer-navbar.html
-
将 display:inline-block 添加到它自己的页脚,我在常见情况下使用它。
标签: html css coding-style styles footer