css底部不动的布局方法[分享][完美]

原理是:

1.定义一个绝对高度为100%的容器,包含min-height属性。所有相关作用的代码置于其中。

2.头部默认布局;

3.布局内容容器(中间)内边距为 指定 px(大于等于footer高度)

4.布局footer为绝对定位。

 

 

原文:

http://codecamel.com/fullheight

 

代码如下:

 

HTML

<body>
    <div id="wrapper">
        <div id="header">Header added just for demonstration purposes</div>
        <div id="content">Main content goes here</div>
        <div id="footer">And this is my footer</div>
    </div>
</body>


 

CSS:

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

#wrapper {
    height: auto !important;
    min-height: 100%;
    height: 100%;
    position: relative; /* Required to absolutely position the footer */
}

#footer {
    height: 50px; /* Define height of the footer */
    position: absolute;
    bottom: 0; /* Sit it on the bottom */
    left: 0;
    width: 100%; /* As wide as it's allowed */
}

#content {
    padding-bottom: 50px; /* This should match the height of the footer */
}


 


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值