I’m trying to build out something with flex that has a layout like this…
[]
[][][]
[][][]
My breakpoints are fine when stacked (1 item per row), or 2 items per row by using
ul {
flex-direction: row;
flex-wrap: wrap;
}
li {
flex: 0 0 48%;
}
li:first-of-type {
flex: 0 1 50%;
}
But once I get to 3 per line the first item doesn’t seem to want to be by itself. I’m fine with having the flex code change with @media breaks, but I need to stay in flex as my last line needs to have any items below 3 centered aligned, not left aligned.
I’ve tried other combinations but have had no luck keeping the first line item the same size as the remaining row items.
2
Answers
Sorry for my late reply, I just got back to this project today. I ended up solving my own problem while trying to make an example on codepen.
Hope this helps anyone else facing the same problem.
(Displays all the profiles in a single column)
(Displays the profiles in 2 columns but keeps the first profile on it's own row centered)
768px + (Displays the profiles in 3 columns but keeps the first profile on it's own row and centered)
One method is to use a grid and position the last/last-but-one items specifically.
This snippet uses a 6 column grid, each item taking up two column widths.
The first item always starts at column 3.
7 grids are shown here, ranging from 1 item to 7.