CSS columns with left-right flow

后端 未结 4 995
攒了一身酷
攒了一身酷 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:19

    Here's a link on solution! Used only flex.

    html

    - var n = 0;
    ul
      while n < 40
        li= n++
      li
    
    

    css

    ul {
        list-style: none;
        padding: 30px;
        background: #28285e;
        
        li {
            padding: 20px;
            margin: 6px;
            background: white;
            width: calc(50% - 52px);
            height: 100px;
            display: inline-block;
            border: {
                radius: 4px
            }
            
            &:nth-child(3n) {
                height: 40px;
            }
            
                
            &:nth-child(2n + 1) {
                height: 80px;
            }
            
            &:nth-child(even) {
                float: right;
            }
            
            &:nth-child(odd) {
                float: left;
            }
            
            &:last-child {
                clear: both;
                float: none;
            }
        }
    }
    

提交回复
热议问题