The flex-basis
property is a sub-property of the Flexible Box Layout module.
It specifies the initial size of the flex item, before any available space is distributed according to the flex factors. When omitted from the flex
shorthand, its specified value is the length zero.
A flex-basis value set to auto
sizes the element according to its size property (which can itself be the keyword auto
, which sizes the element based on its contents).
Syntax
flex-basis: <width> .flex-item { flex-basis: 100px; }
Please note that as for any width, negative lengths are invalid.
Demo
<ul class="flex-container"> <li class="flex-item flex1">1</li> <li class="flex-item flex2">2</li> </ul>
.flex-container { padding: 0; margin: 0; list-style: none; -ms-box-orient: horizontal; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -moz-flex; display: -webkit-flex; display: flex; } .flex-item { background: tomato; padding: 10px; border: 5px solid red; color: white; font-weight: bold; font-size: 2em; text-align: center; } .flex1 { flex: 1 1 20em; } .flex2 { flex: 2 2 20em; }
Related Properties
Browser Support
- (modern) means the recent syntax from the specification (e.g.
display: flex;
) - (hybrid) means an odd unofficial syntax from 2011 (e.g. display: flexbox;)
- (old) means the old syntax from 2009 (e.g. display: box;)
Chrome | Safari | Firefox | Opera | IE | Android | iOS |
---|---|---|---|---|---|---|
21+ (modern) 20- (old) |
3.1+ (old) | 2-21 (old) 22+ (new) |
12.1+ (modern) | 10+ (hybrid) | 2.1+ (old) | 3.2+ (old) |
Blackberry browser 10+ supports the new syntax.
Leave a Reply