rachelandrew / cssgrid-ama

Ask me anything about CSS Grid Layout
328 stars 12 forks source link

grid-gap affecting overall width of grid? #26

Closed bradryanbice closed 7 years ago

bradryanbice commented 7 years ago

As is displayed here: http://codepen.io/bradbice/pen/pRWZrP my grid is pushing out beyond it's max-width thanks to the grid-gap values compounding. The empty box below the grid of photos is the correct max-width. The photo grid is introducing a scroll bar on narrower viewports.

I was under the impression that grid-gap would not affect overall width. Would something else be affecting it? box-sizing properties don't seem to matter.

rachelandrew commented 7 years ago

a grid-gap is treated like a track, so you have created a grid wider than 100%.

Use the fraction unit for your tracks instead as that shares a fraction of the available space.

http://codepen.io/rachelandrew/pen/MJEBZV

bradryanbice commented 7 years ago

@rachelandrew That's it! I knew it was something simple and I was forgetting something. Thank you!