I'm looking at building a data table using css grids. The idea would be that it is ready to be fully responsive. Take the following example: https://jsfiddle.net/9L46zfp7/
body {
margin: 0;
}
.container {
width: 100%;
}
.cssgrid {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-auto-flow: dense;
}
.column {
padding: 10px;
border-bottom: 1px solid black;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.column1 {
grid-column: 1;
background-color: wheat;
}
.column2 {
grid-column: 2;
background-color: palegreen;
}
.column3 {
grid-column: 3;
background-color: lemonchiffon;
}
.column4 {
grid-column: 4;
background-color: lightcyan;
}
.column5 {
grid-column: 5;
background-color: thistle;
}
@media screen and (max-width: 800px) {
.cssgrid {
grid-template-columns: repeat(4, 1fr);
}
.column1 {
grid-column: 1;
grid-row: span 2;
}
.column2 {
grid-column: 2;
border: 0;
}
.column3 {
grid-column: 3;
border: 0;
}
.column4 {
grid-column: 2;
grid-column: span 2;
}
.column5 {
grid-column: 4;
grid-row: span 2;
}
}
<div class="container">
<div class="cssgrid">
<!-- row -->
<div class="column column1">0</div>
<div class="column column2">1</div>
<div class="column column3">2</div>
<div class="column column4">3</div>
<div class="column column5">4</div>
<!-- row -->
<div class="column column1">5</div>
<div class="column column2">6</div>
<div class="column column3">7</div>
<div class="column column4">8</div>
<div class="column column5">9</div>
</div>
</div>
Here, you'll see that when the screen is less than 800px wide, the table rows will "split up" into two rows. Now, I'd really like to switch the green with the blue columns.
Is this possible using css only, knowing that the data is dynamically generated (so I cannot reference any specific column number, the html should remain unchanged)?
Thanks in advance!