Masonry Layout in CSS3?

后端 未结 5 1474
星月不相逢
星月不相逢 2020-12-06 14:47

I try to use the following structure to generate the layout described below.

child 1
5条回答
  •  天命终不由人
    2020-12-06 15:07

    If there are only two columns, why not just use floats, alternating left and right floating/clearing for odd and even boxes?

    .container {
        background-color: yellow;
        overflow: hidden;
        width: 100%;
    }
    .box {
        height: 100px;
        width: 50%;
    }
    .box:nth-child(odd) {
        float:left;
        clear: left;
    }
    .box:nth-child(even) {
        float:right;
        clear: right;
    }
    .box1 {
        background-color: lime;
    }
    .box2 {
        background-color: blue;
        height: 120px;
    }
    .box3 {
        background-color: red;
        height: 140px;
    }
    .box4 {
        background-color: green;
    }
    child 1
    child 2
    child 3
    child 4

提交回复
热议问题