If I set a variable value for grid-gap
like 10%
the padding-bottom
of the parent (<div id="grid">
) starts flowing inside the children (<div class="grid-item">
). Why is that and how can I prevent this behavior?
Here is an minimal example:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#grid {
padding-bottom: 100px;
display: grid;
grid-gap: 10%;
grid-template-columns: 100px;
}
.grid-item img {
width: 100%;
}
<div id="grid">
<div class="grid-item"><img src="https://cdn.sstatic.net/Img/teams/overview/secure.png?v=03c691959884">
<h3>Stack Overflow</h3>
</div>
<div class="grid-item"><img src="https://cdn.sstatic.net/Img/teams/overview/secure.png?v=03c691959884">
<h3>Stack Overflow</h3>
</div>
</div>
You can use the Dev-Tools to inspect the grid-parent (<div id="grid">
) and look at the padding or see this screenshot to see the issue (padding (green) infringing on the space of the grid-elements (dashed boxes)):