0

Is there a css-grid property which locks the grid children to be no bigger than their parent?

I've been using css-grid to create layouts for some time now and one common problem I've been seeing is that the contents of a grid child overflowing their parent container.

When searching the solution to this problem, most of the time, the solution suggested is to set the property of the grid child item to be something like: max-height: 100%, max-width: 100% or overflow:hidden on the child item. But IMO this is not the best way to solve the problem. While building interactive pages where a user might be uploading contents, we might not be able to control the size of content in grid child, instead there should be an option to set in the parent grid, that no matter what, the child grid will not exceed the size initially set or the size of the parent grid. Indeed, one can override this default to their liking if they wanted the child grid item to be able to overflow.

So is there a css-grid or any other css property that I can set while building a grid, so that any of the children are guaranteed to not exceed the size of the parent?

P. Jim
  • 1
  • https://stackoverflow.com/q/43311943/3597276 – Michael Benjamin Dec 29 '18 at 21:16
  • Thanks Michael, reading: https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size Looks like I still would need to either set min-width & min-height to 0 on *child* or set overflow: hidden on *child*. While this does answer on how to keep child contents from overflowing, is there a way to set this on the parent and rest knowing no child items can breach that parent limit? – P. Jim Dec 30 '18 at 00:25
  • Thanks @Michael_B – P. Jim Dec 31 '18 at 19:18

0 Answers0