r/webdev • • Jan 18 '23

CSS flex for speed learners.

6.5k Upvotes

100 comments sorted by

View all comments

17

u/Scoots1414 Jan 18 '23

Can someone explain the layout spacing for space-around? It looks like space-evenly, the outside and inside gutters all have equal distance, makes sense. But for space-around, the gutters on the outside don’t match the gutters between A-B and B-C.

What is the flex calculating to determine the different gutter sizes for the outsides vs insides?

0

u/[deleted] Jan 18 '23

[deleted]

7

u/Scoots1414 Jan 18 '23

Thank you for explaining! Makes so much sense now looking at it again

4

u/Voltra_Neo front-end Jan 18 '23

Same space around each flex item (don't merge spaces)

4

u/r0ck0 Jan 19 '23

Assuming I've understood it correctly, another slightly more visual explanation...

In both cases, the "empty spaces" are all the same size, but it's a bit like if there were a different number of them:

space-around has 6x equal empty spaces:

1a23b45c6

space-evenly has 4x equal empty spaces:

1a2b3c4

Or a JS string analogy:

array.map(item => "_" + item + "_").join("") === "_a__b__c_"
                "_" + array.join("_") + "_"  === "_a_b_c_"

1

u/[deleted] Jan 18 '23

Hah. I was about to ask the same thing.

1

u/TheRNGuy Jan 19 '23

it's like using padding on left and right