I've been trying to wrap me head around css grid. Why doesn't the outer grid grow to the size of the inner grid in this example? How can I fix this layout?
.scroll {
width: 200px;
overflow: auto;
}
.wrapper {
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
border-radius: 2px;
margin: 1rem;
}
.grid {
display: inline-grid;
grid-template-columns: auto auto;
grid-column-gap: 1em;
}
<div class="scroll">
<div class="wrapper">
<div class="grid">
<p>Grid:</p>
<div class="grid">
<p>text here</p>
<p>verylongtextherewithoutanybreakingoptions</p>
</div>
</div>
</div>
</div>
In your example you have two grids AND two other wrappers. Both grid are extended to the same size since they are made inline-grid but it's not the case of the .wrapper where you applied box-shadow.
Make the .wrapper inline-block and it will fix the layout.
.scroll {
width: 200px;
overflow: auto;
}
.wrapper {
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
border-radius: 2px;
margin: 1rem;
display:inline-block;
}
.grid {
display: inline-grid;
grid-template-columns: auto auto;
grid-column-gap: 1em;
}
<div class="scroll">
<div class="wrapper">
<div class="grid">
<p>Grid:</p>
<div class="grid">
<p>text here</p>
<p>verylongtextherewithoutanybreakingoptions</p>
</div>
</div>
</div>
</div>
The outer .grid is always grow up with inner .grid. Which is fixed in here is width of .scroll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With