I was able to solve this by adding position: relative;
to the .grid-container
and position: absolute;
to the svg
and then giving the .content
a z-index:1;
See here:
.top {
padding: 20px;
display: flex;
flex-direction: row;
}
.grid-container {
background-color: red;
display: grid;
width: auto;
position: relative;
}
.svg {
grid-column: 1;
grid-row: 1;
width: 100%;
height: 100%;
position: absolute;
}
.content {
grid-column: 1;
grid-row: 1;
font-size: 100px;
z-index:1;
}
This div has calculated width 300px for some reason
<div class="top">
<div class="grid-container" key="1">
<svg class="svg" viewBox="-10 -10 20 20" preserveAspectRatio="none">
<polygon id="diamond" strokeWidth="0" fill="yellow" points="0,-10 10,0 0,10 -10,0" />
</svg>
<div class="content">
ab
</div>
</div>
<!-- more grid-containers -->
</div>
This works as expected
<div class="top">
<div class="grid-container">
<svg class="svg" viewBox="-10 -10 20 20" preserveAspectRatio="none">
<polygon strokeWidth="0" fill="yellow" points="0,-10 10,0 0,10 -10,0" />
</svg>
<div class="content">
abcdefghijkl
</div>
</div>
<!-- more grid-containers -->
</div>