如何粘贴< footer>元素在页面的底部(HTML5和CSS3)? [英] How to stick <footer> element at the bottom of the page (HTML5 and CSS3)?

查看:190
本文介绍了如何粘贴< 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;
        }

示例:http://jsfiddle.net/a6RBm/

这篇关于如何粘贴&lt; footer&gt;元素在页面的底部(HTML5和CSS3)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆