CSS flex – shorthand for flex-grow, flex-shrink and flex-basis

CSS flex is the shorthand property for flex-grow, flex-shrink and flex-basis. flex-shrink and flex-basis are optional. Its default value is 1 0 auto.

Syntax:

.someflexcontainer {
  display: flex;
}
.flexitem {
  flex: 0 1 20%;
}

CSS property flex

CSS version: CSS 3
Value: [flex-grow] [flex-shrink-optional] [flex-basis-optional]
Initial: 1 0 auto
Applies to: flex items
Inherited: no

Example – flex

In the following code, CSS property flex can be changed to the following values
  • 0 1 20%
  • 1 1 20%
<style>
.fbox {
  display: flex;
  width: 250px; background-color:gray;
}
.child {
  background-color:green;
  padding: 3px; margin: 3px;
  /* flex-grow, flex-shrink, flex-basis */
  flex: 0 1 20%;
}
</style>

<div class=fbox>
<div class="child">div1</div>
<div class="child">div2 long</div>
<div class="child">div3</div>
</div>
flex refresh

Specification and Browser compatibility

SpecificationStatusCategories
Flexible Box Layout ModuleW3C Working DraftCSS3
Desktop
ChromeFirefoxIEEdgeSafariOpera
Yes 29+ Yes 28+ Partial 11+ Yes 12+ Yes 9+ Yes 12.1+
Mobile
Android ChromeAndroid FirefoxiOS SafariIE MobileOpera Mobile
Yes 47+ Yes 44+ Yes 9.0-9.2+ Yes 11+ Yes 12.1+
source: caniuse.com
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments