I’m just learning flexbox and trying to create a list that looks like the attached image:
I’ve been able to figure out how to get list items 1-3, but I’m stuck on getting 4-6 to line up below 1-3.
flex: 0 0 100%;
flex: 0 0 50%;
flex: 0 0 50%;
I’d like to get the margins/gutter spacing between the list items too, but the repeating structure is where I’m currently stuck!
I think to do this with flex, you will need to use the
order property to make every 3rd element starting with
1 be first in order, which will give you the big squares all in the first column, with the smaller squares following in the second column.
I would have a go at throwing a Pen together, but I’m out of time tonight.
OK, not perfect, as it’s a rush job. But it will get you started with the basic principle:-
Gonna start playing with this immediately!
Thanks again Sam!
That’s nice work by Sam, but just be aware that this is a perfect scenario for
display: grid. One of the tricks with using flexbox is knowing when it’s not the best tool.
Was going to mention that, but it slipped my mind as I wanted to try the flex challenge.
I’ve already created this as a CSS Grid, but I’m hopeful to use Sam’s flexbox code as the start of a fallback for current IE, Edge and Safari browsers. Looks like CSS Grid is supported by Safari, but on my Windows 10 machine it breaks in Safari…
And so it should! Safari hasn’t been updated for Windows in many years, and is not a player in the Windows browser market any more.
Grid was released this year for most browsers, so it has pretty good support, but not universal. I think flexbox is a little better supported at this stage. The nice thing about both, though, is that you can arrange simple fallbacks for the browsers without support yet — which would satisfy everyone (web dev and clients) if this were a sane world.
Just to play around (I’m starting learning grid layout )
the same thing with grid layout
You can set the height in the wrapper
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.