Flexbox Froggy
flexboxfroggy.com
flexboxfroggy.com
https://cssgridgarden.com/ (basically Froggy for Grid)
https://cssbattle.dev/ (a platform for doing various challenges, huge community)
https://flukeout.github.io/ (learn about CSS selectors)
https://css-animations.io/ (practice CSS animations)
Opened an Edge window, attempted to sign in: had a long wait followed by an error message about a network failure.
https://css-tricks.com/understanding-flex-grow-flex-shrink-a... (describes flex-grow, flex-shrink, flex-basis)
CSS grid is incredible too. I can’t believe how spoiled we are now with amazing layout options.
Actually though, not really an analog, but surprisingly something not many people are aware enough of - https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical...
Helps a lot when working with applications that need to support both LTR and RTL languages.
I don’t know if that’s the only reason, so I’m not gonna say it was a bad choice. But at least to me, I’m exactly like you in the sense that I can’t remember which one is which. I would have preferred either better naming that references the axis, or simply have the attributes be independent of the parent. Until then, I have to use a cheat sheet.
Further, there's no "bottom to top" mode for horizontal scripts, but vertical modes can have a block axis running either ltr or rtl, affecting the direction of the flex cross axis. Which likely leads to the necessity to also abstract "row-reverse" and "column-reverse" directions for the ordering of items.
now as for distribution of items on either axis (whichever direction it may have), referring rows/columns when might become misleading, and also having to address individual rows (align-content) complicates things. Finding another set of terms for flexbox alone might start to become messy, since display:grid and multicolumn layouts will also require these settings.
I don't know the actual origin of align & justify either, but I have the feeling coming up with better terms might not be that easy
- "justify-" is for the primary axis.
- "align-" for the secondary one
- "-content" is for grid tracks / rows in flex-wrap containers.
- "-items is for individual children (within the row / grid cell)
I would also definitely prefer clearer names.
What's going on with the red text all the way on the left of the news items? It does not appear to be the same thing as the bichig...?
[0] https://css-tricks.com/snippets/css/a-guide-to-flexbox/
[1] https://css-tricks.com/snippets/css/complete-guide-grid/
For items vs content: You always have items no matter what. But you don't need to do anything to the entire content besides justify/align until you have multiple rows with flex-wrap. There's simply no effect that align-content could possibly have here. So items is for individual children, and content is for entire rows.
So tldr: Justify is like the "justify" option in word processors, and align is the opposite one; you always have items, but aligning the content won't change anything until you have 2 rows/cols.
Remember these 2 things and you probably won't forget which is which ever again.
(That said, I do often forget if flex starts out row or column, but that's relatively unimportant to know, because the way I get around this is by always adding the direction when I say "display:flex".)
there are so many shims and polyfills amongst actual solutions now
As an aside, I've learned so many things via games like this. Including vim (via https://vim-adventures.com/), which I now basically can't live without.
https://news.ycombinator.com/item?id=30251054 2022 (317 points, 31 comments)
https://news.ycombinator.com/item?id=22629903 2020 (27 points, 2 comments)
https://news.ycombinator.com/item?id=21796926 2019 (2 points, 0 comments)
https://news.ycombinator.com/item?id=18752031 2018 (3 points, 0 comments)
https://news.ycombinator.com/item?id=18731852 2018 (6 points, 1 comment)
https://news.ycombinator.com/item?id=15605783 2017 (4 points, 0 comments)
https://news.ycombinator.com/item?id=14349739 2017 (3 points, 0 comments)
https://news.ycombinator.com/item?id=10652909 2015 (315 points, 69 comments)
There's also https://codepip.com/games/grid-garden/ by the same author that uses the same approach for CSS Grids.
I enjoyed this game to learn CSS selectors a while ago: https://flukeout.github.io/
In a rush, what would help me refresh flexbox knowledge is being able to drag and drop the frog, snapped to a 3x3 grid, and get the flexbox CSS code as output.
Still a very thoughtful tutorial.
(EDIT: The reason I said the above is I've personally given up on keeping up with new CSS stuff. Having written CSS off and on since IE7 days, basically I have no energy to keep css tricks in memory, having lived through hand coding vendor prefix flags and whatever the new Chrome Canary is thrusting down the pipe)
I’ve found that grids are a little easier to maintain a flat hierarchy and avoid complexity, but the downside is it also doesn’t modularize that well – you need to compose all the cells together, some of which probably should belong in a child “component”.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_la...
I think Safari has it because the guy that wrote the spec now works at Apple. Not 100% sure of that, but seems that way.
The code is in Chromium, just nobody ever hit the GO button.
It would have been much cleaner to add "auto-span" utility to grid-column and grid-row that allow to define "overflow snapping" if items are larger than template definitions, with an option for grid-auto-flow to affect packing logic
This draft feels like it's solving a single use case by stacking presets over the grid api instead of exposing tools to achieve that use case
Amazing educational tool.
Due to the magic of working primarily with perfectly functional but older projects, I only recently got the chance to start using flexbox. I immediately loved it far more than the float/clearfix headache I was used to.
The only thing that trips me up is the difference in naming with justify-content and align-items. I feel should both be (justify|align)-(THE SAME THING).
edit: Just got to 21. Looks like my confusion is common enough that there's a level about it.
- Start with Flexbox. Flexboxes of flexboxes will solve almost everything that’s common, and be easier to reason through and maintain imo.
- If you’re doing something that appears tabular, use Grid. Flexbox will appear as though it’ll get you there, but the moment you start having cell contents that are highly variable in size your columns will start to get out of sync.
- The above is esp the case if you’re trying to do repeating sets of rows. Eg Row type A, row type B, A, B, etc. That’s a Grid problem.
But of course, the only way to get good mental models is by trying both approaches and seeing what the drawbacks are. Maybe try the Grid games that folks have linked in other comments?
- You can align things in 2D space, not just along a single axis (like flex). Great for the top level layout of a site/UI.
- You can have white space. I often create white space (empty grid cell) in my UI so I can add UI elements there if needed later on. Works well with elements that are conditionally rendered, as these will change flex layouts but elements assigned to a grid cell will not move.
So if you wanted, you could just use Grid... although Flexbox could be considered slightly more striaghtforward for 1D stuff.
So, if I need alignment, I go with flexbox. If I have all the elements sketched-up in a design, I go with grid.
flex-wrap: wrap-reverse;
justify-content: center;
align-content: space-between;
The yellow froggies end up separated by wrapping. Then it's just a matter of aligning them. The align-self and order attributes mentioned seem to be red herrings.
That said, flexbox froggy and the other grid garden game were fun. Also find myself regularly going for the css tricks reference page for both of these.
Fun fact: border-radius wasn't supported well until one year (2010) before Bootstrap (2011) was first released. You had to do rounded corners with some annoying background-image hacks.
Not using Tailwind as much these days (more inclined to CSS-in-JS solutions like Stitches, which unfortunately has been abandoned by the developers), but for prototyping it’s still amazing.