Quantcast
Channel: Active questions tagged flexbox - Stack Overflow
Viewing all articles
Browse latest Browse all 1675

GRID CSS - How to center children when grid-column is defined?

$
0
0

I discovered Grid CSS recently. And I was wondering how to center children in the container (that has a display grid) when we got only two children for example. I show you a short preview of my issue.

Here, I defined 12 columns in my container. And we have 4 children with a grid-column: span 4. Everything works fine!

Grid css 01

But now, if we got only 2 children and I want to center them in the grid, how can I do this ? I tried to justify-content: center to my container but it does not working. Of course, I can place children with grid-column: 4/7 (for the first child). But I'd like to do it automatically.

Grid CSS 2

The only solution I found is using Flexbox instead of Grid.

Thanks!


Viewing all articles
Browse latest Browse all 1675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>