I'm having trouble figuring out the best way to organize my grid items on an HTML page. I have several charts, each with a previous and current version. Sometimes the heights of these charts vary, so I decided to create a layout with two columns and multiple rows. The Previous charts will be on the left and the Current charts on the right:
<div class="my-grid">
<div class="chart previous">Previous</div>
<div class="chart current">Current</div>
<div class="chart previous">Previous</div>
<div class="chart current">Current</div>
</div>
However, when the screen becomes narrow, I want all the charts to display in a single column, with the Current charts appearing before the Previous ones. I've attempted using CSS grid, but couldn't figure out how to move the charts to the front or back properly. Using grid-template-areas
resulted in overlapping charts.
If you resize the view to be narrow, the blocks should rearrange so that all the orange Current blocks are at the top, followed by the blue Previous blocks, while maintaining their original order.
Below is an image depicting the desired wide view (which currently works as intended)
https://i.sstatic.net/yrnAL80wm.jpg
Narrow View:
https://i.sstatic.net/oTntvg3Am.jpg
What would be the best approach to achieve this layout using CSS grid, or any other simple CSS technique? I'm open to rearranging the items in the HTML, as long as they appear correctly in the display order.