html - 让页脚粘在页面底部

标签 html css footer

我目前正在 build 一个网站并要求我的页脚贴在页面底部 - 我有点挣扎 - 下面是我的 HTML 和我的 CSS 的示例 - 如果页面很小,但如果它变大,它会随着页面一起增长。 HTML:

<div class="container">
    <div class="main">
        <!-- some content -->
    </div>
</div>
<div class="clear"></div>
    <div id="footer">
        <div class="container">
            <div class="footer_nav">
                <h4>Site Map</h4>
                <ul>
                    <li><a href="index.php">Home</a></li>
                    <li><a href="food.php">Example Page 1</a></li>
                    <li><a href="#">Example Page 2</a></li>
                    <li><a href="#">Example Page 3</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            </div>
            <div class="footer_copy">
                <p>&copy;<?php echo date('Y');?> Oliver Fletcher<br/>
                All Rights Reserved</p>
                <h4>Where I learnt...</h4>
                <img src="images/accreditations.jpg" alt="Team Treehouse">
            </div>
            <div class="footer_social">
                <a href="https://twitter.com/fletcher_oli" target="_blank"><img src="images/twitter.png" alt="Twitter"></a>
                <a href="https://www.facebook.com/oli.fletcher" target="_blank"><img src="images/facebook.png" alt="Facebook"></a>
                <a href="https://www.linkedin.com/e/fpf/183035612" target="_blank"><img src="images/linkedin.png" alt="LinkedIn"></a>
                <a href="https://plus.google.com/106172283538461109605/about" class="google" target="_blank"><img src="images/google.png" alt="Google"></a>
                <h4>Get in touch</h4>
                <a href="mailto:oli@thewebshare.co.uk">oli@thewebshare.co.uk</a>
            </div>
        </div>
        <div class="clear"></div>
    </div>
</body>

CSS

html{
    height: 100%;
}  

.container{
    width: 980px;
    margin: auto;
    min-height: 100%;
    _height: 100%;
}

.main{
    margin-bottom: -183px;
    position: relative;
}

#footer{
width: 100%;
background-image: url('../images/nav_bg.png');
color: white;
font-weight: lighter;
position: relative;
padding: 20px 0;
height: 183px;
}

最佳答案

#footer{
width: 100%;
background-image: url('../images/nav_bg.png');
color: white;
font-weight: lighter;
position: fixed;
bottom:0px;
padding: 20px 0;
height: 183px;
}

使用position:fixedbottom:0px

关于html - 让页脚粘在页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16972936/

相关文章:

javascript - 安卓 View + jquery

javascript - 如何删除按钮中下一个和上一个按钮附近的不同颜色空间

javascript - CSS 按钮动画不起作用

html - Div 不覆盖页面的整个宽度

html - 页脚 Div 位置错误

css - 页脚漂浮在 div 上

javascript - 我怎样才能使特定的 li 在 while 循环中处于事件状态

android - Titanium 1.8 是否终于摆脱了 1.6 和 1.7 版的内存不足问题

php - 使用下拉菜单从表单插入表格

android - 在 RecyclerView 网格中放置一个不确定的进度条作为页脚