I have a wide html-table that I'd like to present for lower screen widths by styling it with pure css.
this is the unstyled table
(the cells are overwide and full of content, this is just an abstract example)
Each row should be a Block with the table cells stacked on top of each other in the same order as in the html source. Then this blocks should be layouted in a grid, so that there are as many blocks next to each other as the screenwidths allows.
Minimal Example
div {
color: grey;
border: 1px solid blue;
width: 600px;
}
body {
padding: 20px;
font-family: Helvetica;
}
.box {
background-color: black;
color: #fff;
padding: 10px;
padding-right: 150px;
font-size: 14px;
}
/*makes desired blocks*/
.wrapper td {
display: block;
}
.wrapper td:last-child {
margin-bottom: 10px;
}
<div>
<table class="wrapper">
<tr>
<td class="box a">A1</td>
<td class="box b">B1</td>
<td class="box c">C1</td>
<td class="box d">D1</td>
<td class="box e">E1</td>
<td class="box f">F1</td>
</tr>
<tr>
<td class="box a">A2</td>
<td class="box b">B2</td>
<td class="box c">C2</td>
<td class="box d">D2</td>
<td class="box e">E2</td>
<td class="box f">F2</td>
</tr>
<tr>
<td class="box a">A3</td>
<td class="box b">B3</td>
<td class="box c">C3</td>
<td class="box d">D3</td>
<td class="box e">E3</td>
<td class="box f">F3</td>
</tr>
<tr>
<td class="box a">A4</td>
<td class="box b">B4</td>
<td class="box c">C4</td>
<td class="box d">D4</td>
<td class="box e">E4</td>
<td class="box f">F4</td>
</tr>
</table>
</div>
This does give me the blocks I want. But I failed so far to arrange the elements in a css grid.
Here is an example of what css I tried:
.wrapper {
display: grid;
grid-auto-flow: row dense;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
grid-auto-rows: minmax(300px, auto);
}
This does work on nested divs as expected (js Fiddle )
I think it brobably has something to do with tables not being allowed to be layouted as grids.
I'd like to avoid making div tables out of my data though, because semantically it is a table and I've heard that this is better for screen teaders and such.
I also tried the various css placement algorithms I looked at the mozilla examples and tried applying them. Also I messed around with setting display:contents for td and tr selectevly

tbody{display:contents}would work too where browser understand it ;)