CSS columns with left-right flow

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

    You can use jQuery to rearrange items in columns. In case of 2 cols it would be:

    $('.your-columns-container .your-item:nth-child(even)').appendTo('.your-columns-container');
    

    https://jsfiddle.net/hzvp7sgf/

    And something more complicated for 3 columns:

    $('.your-columns-container .your-item:nth-child(3n - 1)').addClass('container-col2');
    $('.your-columns-container .your-item:nth-child(3n)').addClass('container-col3');
    
    $('.container-col2').appendTo('.your-columns-container').removeClass('container-col2');
    $('.container-col3').appendTo('.your-columns-container').removeClass('container-col3');
    

    https://jsfiddle.net/d4LeLyu5/

提交回复
热议问题