2

When wide item is positioned within a grid (red, in the picture below), the grid preserves its width.

However, when there is another grid in the game (blue, in the picture below), it overflows the parent grid, and adding width: 100% to it doesn't seem to help.

Why is this happening?

How would you ensure that the blue grid doesn't overflow the red container?

enter image description here

.container {
  width: 200px;
  border: 4px solid black;
}

.grid1 {
  display: grid;
  border: 10px solid red;
  margin-bottom: 40px;
}

.grid2 {
  display: grid;
  border: 10px solid blue;
}

.item {
  width: 300px;
  background-color: #ccc;
}
<div class="container">
  <div class="grid1">
    <div class="item">Item</div>
  </div>
  <div class="grid1">
    <div class="grid2">
      <div class="item">Item</div>
    </div>
  </div>
</div>
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746

0 Answers0