Consider a CSS grid where rows can have variable heights:
.grid {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-column-gap: 16px;
grid-row-gap: 8px;
}
.first {
grid-column: 1 / 3;
background-color: #ccc;
}
.second {
grid-column: 5 / 6;
grid-row: 2 / 5;
background-color: #ccc;
height: 120px;
}
<div class="grid">
<div class="first">First</div>
<div class="second">Second</div>
</div>
When hovering on the grid element in DevTools, Chrome visualizes the grid like this:
How could I achieve a similar grid overlay effect using CSS (or JavaScript, if needed)?
Notes:
- All grid cells should be highlighted, even if grid items don't occupy them.
- Grid cells can have variable heights (in the example above the first row height is smaller than the rest of the rows).
