Style flex Property
Example
Let all the flexible items be the same length, regardless of its content:
for (i = 0; i < y.length; i++) {
y[i].style.flex = "1";
}
Try it Yourself »
Definition and Usage
The flex property sets or returns the length of the item, relative to the rest of the flexible items inside the same container.
The flex property is a shorthand for the flexGrow, flexShrink, and the flexBasis properties.
Note: If the element is not a flexible item, the flex property has no effect.
Browser Support
Property | |||||
---|---|---|---|---|---|
flex | Yes | 11.0 10.0 msFlex |
Yes | 6.1 WebkitFlex | Yes |
Syntax
Return the flex property:
object.style.flex
Set the flex property:
object.style.flex = "flex-grow flex-shrink flex-basis|auto|initial|inherit"
Property Values
Value | Description |
---|---|
flex-grow | A number specifying how much the item will grow relative to the rest of the flexible items |
flex-shrink | A number specifying how much the item will shrink relative to the rest of the flexible items |
flex-basis | The length of the item. Legal values: "auto", "inherit", or a number followed by "%", "px", "em" or any other length unit |
auto | Same as 1 1 auto. |
initial | Same as 0 1 auto. Read about initial |
none | Same as 0 0 auto. |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | 0 1 auto |
---|---|
Return Value: | A String, representing the flex property of an element |
CSS Version | CSS3 |
Related Pages
CSS reference: flex property
HTML DOM STYLE Reference: flexBasis property
HTML DOM STYLE Reference: flexDirection property
HTML DOM STYLE Reference: flexFlow property
HTML DOM STYLE Reference: flexGrow property
HTML DOM STYLE Reference: flexShrink property
HTML DOM STYLE Reference: flexWrap property
❮ Style Object