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

How to make fixed-width CSS Grid items occupy the full width of the parent element? [closed]

$
0
0

I want grid items with a fixed width to span the full width of their parent container, leaving equal spacing between them. In Flexbox, this could be achieved using justify-content: space-between. How can I achieve a similar layout using CSS Grid?

Here’s the example code I’m working with:

.wrapper {  background-color: black;  width: 500px;  margin: 0 auto;  padding: 0 30px;}.grid {  display: grid;  grid-template-columns: repeat(16, 1fr);  justify-items: center;  width: 100%;  gap: 25px;}.grid-item {  background-color: red;  grid-column: span 4;  width: 50px;  height: 50px;}.grid-item:nth-child(5) {   grid-column: 3 / span 4;}
<div class="wrapper"><div class="grid"><div class="grid-item"></div><div class="grid-item"></div><div class="grid-item"></div><div class="grid-item"></div><div class="grid-item"></div><div class="grid-item"></div><div class="grid-item"></div></div></div>

Viewing all articles
Browse latest Browse all 1461

Trending Articles



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