I currently have a simple table with a main container (i.e. display: table). In that container I have some rows (i.e. display: table-row), which then have some divs (i.e. display: table-cell).
.table {
display: table;
margin-bottom: 50px;
}
.table .table-row {
display: table-row;
}
.table .table-row div {
display: table-cell;
padding: 10px;
border: 1px red solid;
}
<div class="table">
<div class="table-row">
<div>Name</div>
<div>Phone</div>
<div>E-mail</div>
<div>City</div>
<div>Last meal</div>
<div>Number of meals</div>
</div>
<div class="table-row">
<div>John Doe</div>
<div>12 34 56 78 910</div>
<div>mail @mail.com</div>
<div>Moscow</div>
<div>1. June 2020</div>
<div>13</div>
</div>
<div class="table-row">
<div>Roger John Doe</div>
<div>12 34 56 78 910</div>
<div>myothermail @myothermail.com</div>
<div>New York</div>
<div>1. September 2020</div>
<div>102</div>
</div>
<div class="table-row">
<div>Roger Rabbit John Doe</div>
<div>12 34 56 78 910</div>
<div>mymail @mymail.com</div>
<div>London</div>
<div>1. May 2020</div>
<div>55</div>
</div>
</div>
Can a CSS grid be used to achieve this same layout, without removing the div which wraps the contents of each row?
I have tried defining a grid on each row. In this case, if you shrink the window, the cells start to collapse, and are no longer aligned with the cells below.
.row-header,
.row {
display: grid;
grid-auto-columns: 1fr;
grid-auto-flow: column;
font-size: 13px;
justify-content: start;
}
.row-header div,
.row div {
padding: 10px;
border: 1px red solid;
}
<div class="row-header">
<div>Name</div>
<div>Phone</div>
<div>E-mail</div>
<div>City</div>
<div>Last meal</div>
<div>Number of meals</div>
</div>
<div class="row">
<div>John Doe</div>
<div>12 34 56 78 910</div>
<div>mail @mail.com</div>
<div>Moscow</div>
<div>1. June 2020</div>
<div>13</div>
</div>
<div class="row">
<div>Roger John Doe</div>
<div>12 34 56 78 910</div>
<div>myothermail @myothermail.com</div>
<div>New York</div>
<div>1. September 2020</div>
<div>102</div>
</div>
<div class="row">
<div>Roger Rabbit John Doe</div>
<div>12 34 56 78 910</div>
<div>mymail @mymail.com</div>
<div>London</div>
<div>1. May 2020</div>
<div>55</div>
</div>