CSS columns with left-right flow

后端 未结 4 1000
攒了一身酷
攒了一身酷 2020-12-03 04:53

Let\'s say I have a div which will contain a set of elements (divs), which may have different heights, but all of them will have the same width.

I\'ve a

4条回答
  •  执念已碎
    2020-12-03 05:02

    If your layout is always going to be 3 columns wide, you could try using the nth selector on your internal divs.
    You could do this by clearing your 4th item.

    #container {
        overflow: hidden;
        width: 440px;
    }
    #container div {
        background-color: gray;
        width: 110px;
        margin: 5px;
        float: left;
    }
    #container div:nth-child(4) {
        clear: both;
    }
    1
    2
    3
    4
    5
    6
    7
    8

    JS Fiddle

提交回复
热议问题