I have a table like this:
<p>On large screens</p>
<table>
<tr>
<td>1</td>
<td>3</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>6</td>
</tr>
</table>
Is there a way to modify it purely with CSS to LOOK like this? (a single column where every odd item is from the first row and every even is from the second row)
<p>On small screens</p>
<div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
I tried to use display: contents;
but apparently, it does not work on <tr>
-s for some reason. Any ideas on how I should approach this? Also, I can only use pure (S)CSS. The number of rows and columns is dynamic.
2
Answers
Use CSS grid like below
Or a very hacky way that I don’t recommend:
You could have the rows overlayed each other, with the rows separated by the total height of each
<td>
element: