如何粘贴< footer>元素在页面的底部(HTML5和CSS3)?
问题描述:
当我使用没有内容的位置相对时,页脚上升,绝对包含大量内容,页脚下移,固定它总是存在。
When I use position relative with no content, footer goes up, with absolute with a lot of content, the footer goes down, and with fixed it is always there.
有没有一种简单的方法来获取在页面的结尾独立于内容,收缩和增长与内容?
Is there a easy way to get at the end of the page independently of the content, shrinks and grows with content?
当有很多内容时,我们可以在第一页看到页脚,当有很少的内容时,我们会在底部看到。
When there is a lot of content we can see the footer in the first page, and when there is few content we will see at the bottom.
<!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>
答
:relative; 到 position:fixed;
For footer change from position: relative;
to position:fixed;
footer {
background-color: #333;
width: 100%;
bottom: 0;
position: fixed;
}