CSS3 & Modern Layouts (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between `flex-grow`, `flex-shrink`, and `flex-basis`?
junior LevelCode ExamplecssBasic
In Simple Words:
Combined into the shorthand: flex: <grow> <shrink> <basis>.
flex-basis: The initial default size of the item along the main axis before free space is distributed (e.g.,200pxorauto).flex-grow: Proportion of available extra space the item absorbs when the container is larger than the sum of children.flex-grow: 2absorbs twice as much remaining space asflex-grow: 1.flex-shrink: Proportion the item shrinks when the container is too small to fit all children.flex-shrink: 0prevents an item from ever shrinking below itsflex-basis.
css
/* Grow to fill space, shrink if needed, initial basis 0 */
.flex-item {
flex: 1 1 0; /* Shorthand for flex: 1 */
}