网页布局中页面内容不足一屏时页脚footer固定底部

网页布局中页面内容不足一屏时页脚footer固定底部

实现样式:
-页面内容不足一屏时页脚固定在底部;
-页面内容超过一屏时,滚动内容到底部时出现页脚;

下面介绍两种方案,第一种方案依赖于浏览器对box-sizing的支持,所以对于低版本IE会有兼容问题,第二种方案对现代浏览器的兼容性无忧。
废话不用多说,直接贴代码啦~

1方案:

代码块语法遵循标准markdown代码,例如:

<!DOCTYPE html>
<html>
<head>
    <title>footer Fix</title>
    <meta charset="utf-8">
    <style>
        *{ 
            margin: 0; 
            padding: 0;
            box-sizing: border-box; 
        }
        html,body {
            height: 100%;
        }
        .header {
            height: 60px; 
            margin-bottom:-60px;
            background: maroon;
            position: relative;
        }
        .content {
            background: #CCC;
            min-height: 100%;
            padding: 60px 0;
        }
        .footer {
            height: 60px;
            margin-top:-60px;
            background: maroon;
        }
    </style>

</head>
<body>
    <div class="header">head</div>
    <div class="content">
        1content</br>content</br>2
    </div>
    <div class="footer">footer</div>
</body>
</html>

2方案

<!DOCTYPE html>
<html>
<head>
    <title>footer Fix</title>
    <meta charset="utf-8">
    <style>
        *{ 
            margin: 0; 
            padding: 0;
        }
        html,body, .wrap{
            height: 100%;
        }
        .head-head {
            height: 60px; 
            background:blue;
        }
        .wrap {
            height:auto;
            min-height: 100%;
        }
        /*.main {padding-bottom: 150px;}*/
        .header {
            height: 60px; 
            background: maroon;
        }
        .content {
            background: #CCC;
        }
        .footer {
            position:relative; 
            clear:both; 
            height: 60px;
            margin-top:-60px;
            background: maroon;
        }
        .clearfix:after {
            content:''; 
            display: block; 
            height: 60px;
            clear: both; 
            visibility: hidden;
        }
        /*.clearfix {display: inline-block;}*/
        /*.clearfix {display: block;}*/

    </style>

</head>
<body>
    <div class="head-head">head-head</div>
    <div class="wrap">
        <div class="mian clearfix">
            <div class="header">head</div>
            <div class="content">   
                1</br>content</br>2
            </div>
        </div>
    </div>
    <div class="footer">footer</div>
</body>
</html>

这里贴出了两种简单的方案,当然还有其他实现方法,待以后慢慢研究。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值