CSS实现footer一直在页面底部

本文介绍了如何使用CSS确保footer始终位于页面底部,即使内容不足一屏时也保持在视口底部。通过示例HTML和CSS代码展示了实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CSS实现footer一直在页面底部,如果文档不够一页,这footer在底部,否则,footer跟随在文档底部

效果图如下:
这里写图片描述

HTML代码如下:

    <div class="wrapper">
        <div class="header">
            <h4>Header</h4>
        </div>
        <div class="container">
            <h4>Container</h4>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>container</p>
            <p>Last Container</p>
        </div>
        <div class="footer">
            <h4>Footer</h4>
        </div>
    </div>

CSS代码如下:

* {
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

.wrapper {
    min-height: 100%;
    position: relative;
}

.header {
    height: 50px;
    background: #999;
}

.container {
    padding-bottom: 100px;
}

.footer {
    background: #999;
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100px;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值