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

In the beginning God created the heavens and the earth.

The Book of John

In the beginning was the Word, and the Word was with God, and the Word was God.

The Book of Genesis

In the beginning God created the heavens and the earth.

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.

 

.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,使容器高度回到原有值,它截断了每一列,这看起来就是我们想要的效果。

 

 

你可能感兴趣的:(软编码)