flex-grow and flex-shrink : accept unitless value that serves as proportion. If an item has flex-grow or flex-shrink value, it grows or shrink. If flex-shrink: 0 , it will not shrink but it will shrink from value of 1.
flex-basis
:It only works if the element is a flex item. It’s not width or height but more like proportion of its axis. if flex-direction: row , this will take space based on x-axis and flex-direction: column , it will take space based on y-axis.
flex
: shorthand for flex-grow, flex-shrink and flex-basis combined. ** It is recommended that you use this shorthand property rather than set the individual properties.
It’s good to use for responsive design! If elements are flex item and have value of flex-wrap: wrap , flex items goes to the next line automatically when the screen gets smaller.
flex-flow
It’s a shorthand for the flex-direction and flex-wrap. The default value is row and nowrap.
/* example */.containerflex-flow:columnwrap;>
Flexbox practice
lang="ko">charset="UTF-8">http-equiv="X-UA-Compatible"content="IE=edge">name="viewport"content="width=device-width, initial-scale=1.0">rel="stylesheet"href="../reset.css">bodydisplay:flex;box-sizing:border-box;width:100%;display:flex;flex-direction:column;>headerwidth:100%;display:flex;justify-content:center;align-items:center;background-color:#2d3436;>navwidth:96%;display:flex;justify-content:center;align-items:center;background-color:#dfe6e9;>navuldisplay:flex;flex-direction:row;align-items:center;justify-content:space-evenly;width:92%;background-color:#74b9ff;margin:020px;>ulliwidth:30%;background-color:#e84393;margin:014px;>mainwidth:100%;background-color:#dfe6e9;display:flex;flex-direction:row;justify-content:center;align-items:center;flex-wrap:wrap;>sectiondisplay:flex;width:70%;justify-content:space-around;align-items:center;width:72%;background-color:#00cec9;>articlewidth:45%;background-color:#dfe6e9;margin:20px;>asideflex:1;background-color:#636e72;>footerwidth:100%;background-color:#fdcb6e;>@mediascreenand(max-width:1000px)sectiondisplay:flex;width:100%;flex-wrap:wrap;>articlewidth:80%;>>menumenumenumenuLorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati asperiores, saepe nihil nulla laborum eligendi rerum possimus ullam doloribus iure quis, quos soluta vero quas esse voluptatibus fuga numquam fugiat? Modi, quo! Aspernatur ullam sed maxime illum quisquam voluptatibus incidunt dolorum sint non fuga excepturi veniam ratione nihil, culpa temporibus reprehenderit aliquam voluptas eius obcaecati itaque atque aperiam odio. Deserunt.Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sequi commodi provident delectus beatae dolorem explicabo fugit, maxime sit modi cum saepe dolores recusandae! Nostrum unde sequi, provident hic alias nisi. Corrupti provident blanditiis tempore. Magni facilis incidunt fugiat quis quasi corrupti cum ut laudantium eum, hic recusandae cupiditate consequatur, magnam, eligendi vero odio sit reprehenderit placeat dolores esse officia. Incidunt?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sequi commodi provident delectus beatae dolorem explicabo fugit, maxime sit modi cum saepe dolores recusandae! Nostrum unde sequi, provident hic alias nisi. Corrupti provident blanditiis tempore. Magni facilis incidunt fugiat quis quasi corrupti cum ut laudantium eum, hic recusandae cupiditate consequatur, magnam, eligendi vero odio sit reprehenderit placeat dolores esse officia. Incidunt?footer
Baseline is determined by this web feature being supported on the current and the previous major versions of major browsers.
The flex CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex container.
Try it
Constituent properties
This property is a shorthand for the following CSS properties:
Syntax
/* Keyword values */ flex: auto;flex: initial;flex: none;/* One value, unitless number: flex-grow flex-basis is then equal to 0. */flex: 2;/* One value, width/height: flex-basis */flex: 10em;flex: 30%;flex: min-content;/* Two values: flex-grow | flex-basis */flex: 1 30px;/* Two values: flex-grow | flex-shrink */flex: 2 2;/* Three values: flex-grow | flex-shrink | flex-basis */flex: 2 2 10%;/* Global values */flex: inherit;flex: initial;flex: revert;flex: revert-layer;flex: unset;
The flex property may be specified using one, two, or three values.
One-value syntax: the value must be one of:
a valid value for : then the shorthand expands to flex: 1 0 .
a valid value for : then the shorthand expands to flex: 1 1 .
the keyword none or one of the global keywords.
The first value must be a valid value for flex-grow .
The second value must be one of:
a valid value for flex-shrink : then the shorthand expands to flex: 0 .
a valid value for flex-basis : then the shorthand expands to flex: 1 .
a valid value for flex-grow .
a valid value for flex-shrink .
a valid value for flex-basis .
Values
The item is sized according to its width and height properties. It shrinks to its minimum size to fit the container, but does not grow to absorb any extra free space in the flex container. This is equivalent to setting » flex: 0 1 auto «.
The item is sized according to its width and height properties, but grows to absorb any extra free space in the flex container, and shrinks to its minimum size to fit the container. This is equivalent to setting » flex: 1 1 auto «.
The item is sized according to its width and height properties. It is fully inflexible: it neither shrinks nor grows in relation to the flex container. This is equivalent to setting » flex: 0 0 auto «.
Defines the flex-grow of the flex item. Negative values are considered invalid. Defaults to 1 when omitted. (initial is 0 )
Defines the flex-shrink of the flex item. Negative values are considered invalid. Defaults to 1 when omitted. (initial is 1 )
Defines the flex-basis of the flex item. A preferred size of 0 must have a unit to avoid being interpreted as a flexibility. Defaults to 0 when omitted. (initial is auto )
Description
For most purposes, authors should set flex to one of the following values: auto , initial , none , or a positive unitless number. To see the effect of these values, try resizing the flex containers below:
The «flex: initial» item takes up as much space as its width requires, but does not expand to take up any more space. All the remaining space is taken up by «flex: auto».
When you click «flex: auto», we set «flex: initial»‘s display property to none , removing it from the layout. The «flex: auto» item then expands to occupy all the available space in the container.
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 17, 2023 by MDN contributors.