Skip to content Skip to sidebar Skip to footer

Wrapping Css Grid And Streching One Grid Item To Take Up All Empty Columns

I'm trying to make the last grid item fill all empty columns in a css grid that has auto-fit for wrapping items. I've read Expand a div to fill the remaining width and Make last el

Solution 1:

It can be achieved with display: flex. In addition, it is necessary to use flex-grow property.

As mdn says about flex-grow:

The flex-grow CSS property sets the flex grow factor of a flex item's main size

* {
  box-sizing: border-box;
}

.flex-container {
  display: flex;
  flex-wrap: wrap;
}

.flex-element {
  width: 10%;
  border: 1px solid #000;
  flex-grow: 1;
  min-height: 120px;
  box-sizing: border-box;
  margin: 05px10px;
  justify-content: space-between;
  text-align: center;
}
<divclass="flex-container"><divclass="flex-element">
      1
    </div><divclass="flex-element">
      2
    </div><divclass="flex-element">
      3
    </div><divclass="flex-element">
      4
    </div><divclass="flex-element">
      5
    </div><divclass="flex-element">
      6
    </div><divclass="flex-element">
      7
    </div></div>

Post a Comment for "Wrapping Css Grid And Streching One Grid Item To Take Up All Empty Columns"