2

I want to achieve 12 column grid behavior similar to what Bootstrap has, but using CSS grids.

  1. I need to have a fixed gaps in pixels
  2. And have a 12 column grid, so I can decide how to place the children.

I'm facing the issue, that combination of grid-template-columns and column-gap doesn't shrink the columns on a smaller screens, but cause horizontal overflow on a screen.

How can I achieve expected behavior with shrinking without reducing the number of columns and keeping the gap in pixels.

DEMO:

.parent {
  max-width: 300px;
  height: 500px;
  overflow: auto;
  border: 1px solid blue;
}

.box {
  grid-column: span 6 / span 6;
  background: red;
  height: 40px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 40px;
}
<div class="parent">
  <div class="grid">
    <div class="box"></div>
    <div class="box"></div>
  </div>
</div>
Pavlo Zhuravlov
  • 323
  • 4
  • 9
  • 1
    40px of gap *11 = 440px > 300px of your container – Temani Afif Nov 11 '21 at 20:58
  • @TemaniAfif Thank you for answer! Does it mean that it's not possible to achieve described behavior? – Pavlo Zhuravlov Nov 11 '21 at 21:11
  • you can like https://codepen.io/link2pk/pen/bGrJyGZ?editors=1100 Resource wes bos https://www.youtube.com/watch?v=FFwgFpyssjo&list=PLu8EoSxDXHP5CIFvt9-ze3IngcdAc2xKG&index=23&ab_channel=WesBos – Praveen Nov 22 '21 at 14:26

0 Answers0