Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square Blocks with Flex Box

Is there a way to get all boxes to be equal to the height (and width) of the largest box using display: flex; with flex-wrap: wrap;. It appears to only work on folks in the same line. This pen illustrates the problem some more: http://codepen.io/komplexb/pen/gbqgXq

like image 475
komplexb Avatar asked Dec 10 '25 00:12

komplexb


1 Answers

Given that you are already setting a height on the parent element (and that the parent element is square), you would just need to give the children flexbox items a height of 50%.

In doing so, the flex-basis (shorthand) value of 50% combined with a height of 50% will result in perfectly square flexbox items since the parent is square.

Updated Example

li {
  flex: 0 0 50%;
  height: 50%;
  color: white;
  text-align: center;
}
like image 147
Josh Crozier Avatar answered Dec 14 '25 04:12

Josh Crozier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!