css布局多列等高且高度自适应

<div class="container">
    <div class="col col-a">
        <p>In the beginning God created the heavens and the earth.</p>
    </div>
    <div class="col col-b">
        <h2>The Book of John</h2>
        <p>In the beginning was the Word, and the Word was with God, and the Word was God.</p>
    </div>    
    <div class="col col-c">
        <h2>The Book of Genesis</h2>
        <p>In the beginning God created the heavens and the earth.</p>
        <p>Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.</p>
    </div>
</div>

 

.container{
    zoom:1; /* for IE6 */
    overflow:hidden;
}
.col{
    float:left; 
    padding-bottom:3000px;
    margin-bottom:-3000px; 
}
.col-a{ 
    width:240px;
    background:#FDFD97;
}
.col-b{
    width:280px;
    background:lightgreen;
}
.col-c{
    width:320px;
    background:#E0DCDC;
}

   这个布局技巧的原理是:我们设置每一列的padding-bottom足够大(根据盒模型,背景色存在于padding上),但这撑大了外层容器的高度,接着我们通过设置列的margin-bottom为负值(绝对值与padding-bottom相等),并且外层容器的overflow为hidden,使容器高度回到原有值,它截断了每一列,这看起来就是我们想要的效果。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值