Using flex for `.flow-content` utility

Why use a margin-top/bottom rather than something like
.flow-content {
display: flex;
flex-direction: column;
gap: 1.2em;
}
.flow-content {
display: flex;
flex-direction: column;
gap: 1.2em;
}
140 Replies
b1mind
b1mindโ€ข7mo ago
why not just use grid/gap ๐Ÿ˜„
tomatao
tomataoOPโ€ข7mo ago
Yeah, just the same...
b1mind
b1mindโ€ข7mo ago
its not
แผ”ฯฯ‰ฯ‚
the gap is the space between elements inside the flex/grid
tomatao
tomataoOPโ€ข7mo ago
I'm saying it's the same in regards to the question, as in... why not... I'm not saying flex and grid are the same ๐Ÿคฆ๐Ÿปโ€โ™‚๏ธ
b1mind
b1mindโ€ข7mo ago
Just depends what you need.
แผ”ฯฯ‰ฯ‚
why use margin-top and bottom? because it's not the same as the gap you can't directly compare both because they do different things, even if they look like they do the same
b1mind
b1mindโ€ข7mo ago
You might not want your children to be flex/grid block elements behave different
tomatao
tomataoOPโ€ข7mo ago
The result is pretty much the same in an easier to interpret rule than:
.flow-content > * + * {
margin-top: 1.2em;
}
.flow-content > * + * {
margin-top: 1.2em;
}
Which is recommended
b1mind
b1mindโ€ข7mo ago
For me this question boils down to how I want children to behave. Grid and Block are going to keep width: 100% by default
แผ”ฯฯ‰ฯ‚
that's not the same as gap
b1mind
b1mindโ€ข7mo ago
If for some reason I don't want grid children but block I'm going to use margin-bottom
tomatao
tomataoOPโ€ข7mo ago
I'm just talking about it in the context of a recommended utility - not a specific case
b1mind
b1mindโ€ข7mo ago
what recommended utility? Oh Kevins flow again cause you are not changing the children
tomatao
tomataoOPโ€ข7mo ago
The visual result is mostly the same bar exceptions
แผ”ฯฯ‰ฯ‚
no, it isn't nowhere close
b1mind
b1mindโ€ข7mo ago
Flex def changes the children xD
tomatao
tomataoOPโ€ข7mo ago
Lol I achieved the same result by doing the above rule so sure
b1mind
b1mindโ€ข7mo ago
You think that but its not ๐Ÿ˜„
แผ”ฯฯ‰ฯ‚
margin-top sets a margin at the top, while gap separates the elements vertically AND horizontally
tomatao
tomataoOPโ€ข7mo ago
Can you see flex?
b1mind
b1mindโ€ข7mo ago
open dev tools
tomatao
tomataoOPโ€ข7mo ago
I said visual result
แผ”ฯฯ‰ฯ‚
it's not the same margins can compound
tomatao
tomataoOPโ€ข7mo ago
collapse*
แผ”ฯฯ‰ฯ‚
and gap does VERTICAL AND HORIZONTAL it won't be the same as margin top and bottom
tomatao
tomataoOPโ€ข7mo ago
It's set to direction "column" in my helper
b1mind
b1mindโ€ข7mo ago
which changes things again
แผ”ฯฯ‰ฯ‚
also, margins have to be manually set to do not apply to the first and last elements, depends on what you do
b1mind
b1mindโ€ข7mo ago
again making children flex children, and changing the axis is not always what you want.
แผ”ฯฯ‰ฯ‚
which, again, gap does automatically
tomatao
tomataoOPโ€ข7mo ago
The helper above excludes the first element as it's using * + * The recommended one
b1mind
b1mindโ€ข7mo ago
Again for me it all comes down to what type of child/parent relationship I need.
แผ”ฯฯ‰ฯ‚
but doesn't exclude the last element
tomatao
tomataoOPโ€ข7mo ago
The helper also assumes something with not inline formatting - to be flow content Yeah, that's the point
แผ”ฯฯ‰ฯ‚
gap doesn't care about the display but margin does
tomatao
tomataoOPโ€ข7mo ago
Right well gap does care... Ain't gonna do much to inline elements
แผ”ฯฯ‰ฯ‚
not really, it doesn't
b1mind
b1mindโ€ข7mo ago
neighter does margin-block
tomatao
tomataoOPโ€ข7mo ago
no, really it does
b1mind
b1mindโ€ข7mo ago
will do nothing to inline elements
tomatao
tomataoOPโ€ข7mo ago
Yeah I never said margin doesn't care ๐Ÿคท๐Ÿปโ€โ™‚๏ธ
แผ”ฯฯ‰ฯ‚
gap doesn't care
No description
b1mind
b1mindโ€ข7mo ago
any way the flow utility is for block children, if you want flexy children use flex, if you want grid use grid.
tomatao
tomataoOPโ€ข7mo ago
Oh wait lol, you're saying it doesn't care about CHILDREN, please complete your sentences
b1mind
b1mindโ€ข7mo ago
flex column is ๐Ÿคข imo unless you are changing it from row for like mobile 90% of the time you just want block elements or grid
แผ”ฯฯ‰ฯ‚
today i learned something: inline elements don't apply the margin unless when they are children of flex or grid
b1mind
b1mindโ€ข7mo ago
that is because they are no longer inline
tomatao
tomataoOPโ€ข7mo ago
they aren't inline
b1mind
b1mindโ€ข7mo ago
but flex/grid children
tomatao
tomataoOPโ€ข7mo ago
^
แผ”ฯฯ‰ฯ‚
i do have a question i will test now
tomatao
tomataoOPโ€ข7mo ago
Why do you not like flex column?
b1mind
b1mindโ€ข7mo ago
Because its counter productive
tomatao
tomataoOPโ€ข7mo ago
Why?
b1mind
b1mindโ€ข7mo ago
You are using Flex but changing is axis children a max-content by default not filling the parent
แผ”ฯฯ‰ฯ‚
it's like putting every block in the square hole
b1mind
b1mindโ€ข7mo ago
Like if you are just wanting vertical content (with control over children, or gap) use Grid
แผ”ฯฯ‰ฯ‚
there's a better hole for the circle, so, why are you forcing it into the square hole? it fits, you can use flex for columns, but you're fighting against flex's ways assuming you want columns with the exact same width if you want it to flex, it may have some uses, like a sidebar or something
b1mind
b1mindโ€ข7mo ago
Most the time you want things to fill too idk why people always lean to flex then have to fuk with magic numbers %'s and shit
แผ”ฯฯ‰ฯ‚
oh god, that's a pain in flex with grid, it's automatic
b1mind
b1mindโ€ข7mo ago
Not to mention when you want sizing based on siblings
แผ”ฯฯ‰ฯ‚
and have any expectations of anything being aligned too
b1mind
b1mindโ€ข7mo ago
people I think just have no clue how flex even works ๐Ÿคฃ cause changing the axis can be powerful but it changes the behavior of flex-basis/shrink/stretch (which maybe what you want) and justify/align. Which imo is stupid if you are just wanting vertical content... now you have alignment for justify etc etc. When 90% of the time you should just be using Block or Grid ๐Ÿ˜„
tomatao
tomataoOPโ€ข7mo ago
The context I had was vertical stack with center aligned blocks of different height. I found a flex column with align-items: center a way more convenient helper than grid for this
แผ”ฯฯ‰ฯ‚
something like masonry?
tomatao
tomataoOPโ€ข7mo ago
I haven't explored masonry yet Just see it in news feeds
b1mind
b1mindโ€ข7mo ago
I would have to see the example, cause Grid is 10x more powerful for centering content/items
tomatao
tomataoOPโ€ข7mo ago
place-content: center <- helps
b1mind
b1mindโ€ข7mo ago
exactly I get triggered when I read align-items and its centering horizontally personally ๐Ÿคฃ
tomatao
tomataoOPโ€ข7mo ago
Actually place-content: center hasn't solved it
แผ”ฯฯ‰ฯ‚
nobody does that, right???? ๐Ÿ˜…
b1mind
b1mindโ€ข7mo ago
again you would have to show us an example, I can't assume what you are doing nore the html.
แผ”ฯฯ‰ฯ‚
yeah, it's better if you show us some code at this point, we're nearly literally grasping at straws, trying to guestimate what might be
b1mind
b1mindโ€ข7mo ago
Whats worse is when I see a <ul> with flex direction on it
แผ”ฯฯ‰ฯ‚
oh lord
b1mind
b1mindโ€ข7mo ago
TW users love using <ul>'s with flex/direction col
แผ”ฯฯ‰ฯ‚
that's a quick way to get rid of the list marks, but it looks so weird and the code is so dumb
tomatao
tomataoOPโ€ข7mo ago
I'm just refactoring a working and easy utility from flex to your grid solution - i shouldn't need help or it kinda ruins your point
b1mind
b1mindโ€ข7mo ago
My only point is knowing the child parent relationship and how children behave differently between the three
tomatao
tomataoOPโ€ข7mo ago
only solution I've found so far with this grid is to justify-self: center on the inline-block child of this "now" grid
แผ”ฯฯ‰ฯ‚
๐Ÿค”
tomatao
tomataoOPโ€ข7mo ago
the codepen you shared also doesn't handle inline-block elements - but I guess it's weird to put them as children of a grid - they should be grid children... just might be helpful for sizing to rely on an anonymous box and the flex solution can handle them
b1mind
b1mindโ€ข7mo ago
Still not sure of your use case so no clue
tomatao
tomataoOPโ€ข7mo ago
vertical stack with center aligned blocks of different height, one of them inline-block some equal spacing between each of them but moreso... a convenient utilty for "flow-content" that with the least drawbacks and easy to comprehend for junior devs I came here assuming that the margin solution was the most battle tested and wanted to understand the pitfalls of alternatives (given it's recommended)
b1mind
b1mindโ€ข7mo ago
Again just depends on do you want those children to shrink to max-content by default
tomatao
tomataoOPโ€ข7mo ago
reasonable answer
b1mind
b1mindโ€ข7mo ago
Block/grid content will fill to the 100% of its parent by default, flex by default does a max-content on each child. Difference with block and grid would be grid children will fill to the largest grid track, block would be independent of siblings
tomatao
tomataoOPโ€ข7mo ago
makes sense - any team could adapt to either default - sounds a bit subjective cool
b1mind
b1mindโ€ข7mo ago
Grid will also max-content children with things like justify-self/align-self. or if defined direction in the template. So yea its one big ol #depends what you need on this one ๐Ÿ˜„ if most your child content is block elements use margin-top/bottom I tend to use it all honestly...
แผ”ฯฯ‰ฯ‚
i just use what feels right except floats! floats suck
b1mind
b1mindโ€ข7mo ago
coding with vibes is ๐Ÿ”ฅ
tomatao
tomataoOPโ€ข7mo ago
again, trying to focus on the generalised utility here rather than specifics
แผ”ฯฯ‰ฯ‚
the problem is that ... there's no generalized advice, in the end it's just about what you want to happen and the tools you have available
b1mind
b1mindโ€ข7mo ago
so like flow content > * + * is really handy when you have article content Specially if you are using a funky reset that removes margins from headings and <p>s Gap is really handy when you need spacing in your layout
แผ”ฯฯ‰ฯ‚
and you use grid/flex it's amazing to keep everything aligned and separated a problem with old tech was to keep everything separated
tomatao
tomataoOPโ€ข7mo ago
I think the point here for a generalised advice would be that using an margin only solution without changing the display will interfere less with existing flow and align more closely with what's been practiced more in the past of course, doesn't stop people from utilising the grid/flex solutions in context
b1mind
b1mindโ€ข7mo ago
yea I'd agree with that In the end you know what really does it for Utility classes is just having it documented in the design system >.>;; clear example and use cases
tomatao
tomataoOPโ€ข7mo ago
also, less declarations
b1mind
b1mindโ€ข7mo ago
Also you can now do some pretty powerful selectors so you could do a check to see if it has a grid/flex util class on it and change it from margin to gap ๐Ÿง  .flow:has(.grid) {} ? or what not .flow:not(.flex) {}
tomatao
tomataoOPโ€ข7mo ago
having written extensive documentation for a company wide design system and monitoring usage of those docs.. i can tell you that people only read examples and play around with the interactive controls or use the getting started guide ๐Ÿ˜“ barely anyone reads the detailed nuanced bits - they're all too busy delivering features
b1mind
b1mindโ€ข7mo ago
is bad at the new selectors needs to practice himself yea I could see that, its good you have both though. Interactive is teh way imo.
tomatao
tomataoOPโ€ข7mo ago
yeah, works if you have utilities for grid and flex.. clever.. but not if you don't
b1mind
b1mindโ€ข7mo ago
right but same could be used for any ๐Ÿ˜„
tomatao
tomataoOPโ€ข7mo ago
aye thanks, got good answers eventually... after y'all being grid snobs about flex-column
b1mind
b1mindโ€ข7mo ago
lol I'm a grid snob period I think people overuse flex when grid is what they need.
tomatao
tomataoOPโ€ข7mo ago
it's existed for longer
b1mind
b1mindโ€ข7mo ago
its my new "don't use vh/vw" rant flex gap is only supported to 2020 where grids is 2017 so ...
tomatao
tomataoOPโ€ข7mo ago
wait, surely that' an IE/edge stat
b1mind
b1mindโ€ข7mo ago
I had cases where I was having to support outdated users and had to use margin-left (for flex navigations) safari/chrome Both are locked behind OS updates too so its not just a browser update
tomatao
tomataoOPโ€ข7mo ago
i guess i'm talking about the display property rather than the gap as that's the gateway to these things
b1mind
b1mindโ€ข7mo ago
Never had a user not support grid had them not support flex gap though ๐Ÿ˜‰
tomatao
tomataoOPโ€ข7mo ago
okay, well i have
b1mind
b1mindโ€ข7mo ago
IE 11 supports grid even hell IE birthd grid xD ms-grid was first I think
แผ”ฯฯ‰ฯ‚
grid is OOOOOOOOLD
b1mind
b1mindโ€ข7mo ago
Again I fight people with grid reluctance its 2024 ffs Stupid to not be using it all over imo like making websites with a hand tied behind your back
tomatao
tomataoOPโ€ข7mo ago
I had to preach grid to a team of seniors who built a design system for just one rule 2 years ago i was their tech lead so i had weight in the conversation too but people are just more comfortable with flex, it has been around for longer lots of people learned from someone who was writing CSS long before 2017
แผ”ฯฯ‰ฯ‚
but grid exists before 2017, no?
tomatao
tomataoOPโ€ข7mo ago
full support in 2017 it existed in IE before I definitely remember many years of waiting for full grid support and fighting some weird flex quirks using min-width: 0 (or was it 1px?) and shit
แผ”ฯฯ‰ฯ‚
sounds like that was an ie hack
tomatao
tomataoOPโ€ข7mo ago
it was on chrome
b1mind
b1mindโ€ข7mo ago
its for inputs to shrink a hack they wanted to make default in TW ๐Ÿคข (recently)
แผ”ฯฯ‰ฯ‚
i get why they want it
b1mind
b1mindโ€ข7mo ago
* { min-width: 0;} was purposed preposed? w/e
แผ”ฯฯ‰ฯ‚
proposed
b1mind
b1mindโ€ข7mo ago
Kevin Powell
YouTube
Is this a good idea?
After Adam Wathan, and then @t3dotgg both posted and talked about the min-width: 0 thing, I've been getting a lot of questions about what I think about it. Rather than just share my own opinion on it (which we will get into), I saw it as a fun opportunity to dive into how Flexbox works and why this can sometimes solve some strange issues, but al...
b1mind
b1mindโ€ข7mo ago
damn I failed 2x
แผ”ฯฯ‰ฯ‚
and english is my 2nd language ๐Ÿคฃ i can see why tailwind wanted to make that the default
b1mind
b1mindโ€ข7mo ago
we have derailed this train
แผ”ฯฯ‰ฯ‚
the bundle size probably drops 1mb from removing all the "classes" needed for that hack oh, yeah, completely in short: grid good, flex good, use where makes sense
b1mind
b1mindโ€ข7mo ago
block good too xD (with flow util*)
แผ”ฯฯ‰ฯ‚
floats bad, except for images
Kevin Powell
Kevin Powellโ€ข7mo ago
@tomatao I realize this conversation carried on to other topics, but my skim through didn't seem to address the most important reason margin and gap aren't the same, which is that gap will always be equal, while margin, if set in em will depend on the font-size of the element, which is a good thing in a lot of situations. If I missed where this came up, I apologize ๐Ÿ˜…
Kevin Powell
Kevin Powellโ€ข7mo ago
I made a video on this actually ๐Ÿ˜„ https://youtu.be/Gx0iZrN-0L4
Kevin Powell
YouTube
CSS gap is NOT a replacement for margins
Iโ€™ve seen some people completely abandoning margins and turning to using gap for everything, and to me, thatโ€™s problematic. Donโ€™t get me wrong, gap is an absolute lifesaver, especially when it comes to spacing out components. What itโ€™s not best for, however, is spacing out regular flow content like text. So, this isnโ€™t to say that you should n...
tomatao
tomataoOPโ€ข7mo ago
Oh really ? I'd expect the scaling to only depends on the units used. So gap doesn't scale? Mad
Kevin Powell
Kevin Powellโ€ข7mo ago
Well, 1.2em would scale, but it's from the parent element where the grid is defined, not the children. With the .flow > * + *, we're directly targetting each child, so it scales independently for each one. Now, sometimes you want even spacing. It's common in, say, a card or form. Then, grid with gap all the way.
Want results from more Discord servers?
Add your server