99

Say I'm doing 3 flex columns, first one 50%, the other two auto adjust.

.half {
    flex: 0 0 auto ;
    width: 50% ;
}

or

.half {
    flex: 0 0 50%;
}

These seem to be functionally the same. Are they?

1
  • 3
    A Closed Question received ~90 Up Votes. Commented Jun 1, 2023 at 21:25

1 Answer 1

145

The bottom statement is equivalent to:

.half {
   flex-grow: 0;
   flex-shrink: 0;
   flex-basis: 50%;
}

Which, in this case, would be equivalent as the box is not allowed to flex and therefore retains the initial width set by flex-basis.

Flex-basis defines the default size of an element before the remaining space is distributed so if the element were allowed to flex (grow/shrink) it may not be 50% of the width of the page.

I've found that I regularly return to https://css-tricks.com/snippets/css/a-guide-to-flexbox/ for help regarding flexbox :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.