I have a two-column layout with several elements inside:
.grid { column-count: 2; } .grid-item { break-inside: avoid; height: 50px; margin-bottom: 10px; background-color: green; text-align: center; line-height: 50px; color: white; }
<div class="grid"> <div class="grid-item">1</div> <div class="grid-item">2</div> <div class="grid-item">3</div> <div class="grid-item">4</div> <div class="grid-item">5</div> </div>
https://codepen.io/Deka87/pen/RgdLeZ
Now I need the ability to reorder these elements inside the columns using CSS only (so they were in a different order at different screen resolutions), so I thought I could do it with
.grid { display: flex; flex-direction: column; column-count: 2; } .grid-item:nth-child(1) { order: 5; }
Obviously, this did not work and broke the two-column layout. Has anyone tried to solve this before? Any chance I can get this to work?
PS: Elements of the same line should not have the same height (in this case, I could use simple floats). Sorry for not specifying at the beginning.
source share