property

flex — CSS reference

Shorthand for grow, shrink and basis. Initial longhands are 0 1 auto; shorthand omitted components normally become 1, 1 and zero basis respectively. The specification describes zero length for omitted basis; browsers commonly expand a lone number to 0%, which matters with indefinite main size. Explicit three-component syntax avoids ambiguity.

Formal Syntax & Structure

css syntaxcss
none | [ <number [0,∞]> <number [0,∞]>? || <flex-basis> ]

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS flexible sizing lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#p{display:flex;width:300px;align-items:flex-start;background:#e6eef2} #p>*{box-sizing:content-box;min-width:0;height:30px;background:#128579;color:white} #b{background:#326c9d}#a{flex:1}#b{flex:2 1 0px}</style><body><div id="p"><div id="a">A</div><div id="b">B</div></div></body></html>
CSS Reference