E
E
eugene1592021-07-01 22:20:22
css
eugene159, 2021-07-01 22:20:22

How do flex-grow: 1 and flex-shrink: 1 set at the same time work? Don't they contradict each other?

Sometimes in the code I saw this:

flex-grow: 1;
flex-shrink: 1;

How do they work together? I wrote an example on jsfiddle, but I can't understand the logic there.
Don't these properties contradict each other? flex-grow increases the width (relative to other elements within the flex container, making the element "greedy"), and flex-shrink decreases it (making the element "generous").

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2021-07-01
@mmmaaak

flex-grow sets the behavior of child elements when the width of the container is greater than the total width of the children, roughly speaking how they will occupy the space that has appeared
flex-shrink sets the behavior when the width of the container is less than the total width of the child elements, roughly speaking how the children will behave elements, when there is not enough space for everyone, who will shrink how

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question