8000 csswg-drafts/css-flexbox/Overview.html at 9efca8e1c99f0546dec1a22e7ff2718781c5faaf · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
4207 lines (4189 loc) · 321 KB

File metadata and controls

4207 lines (4189 loc) · 321 KB
<!doctype html><html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>CSS Flexible Box Layout Module Level 1</title>
<meta content="testing" name="csswg-work-status">
<meta content="ED" name="w3c-status">
<link href="../default.css" rel="stylesheet" type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
<meta content="Bikeshed 1.0.0" name="generator">
<script defer="" src="//test.csswg.org/harness/annotate.js#css-flexbox-1_dev/css-flexbox-1" type="text/javascript"></script>
<style>
#axis-mapping-table [rowspan=8] { writing-mode: sideways-lr; }
#axis-mapping-table a { white-space: nowrap; }
</style>
<style>
code.one-line { white-space: pre; }
.code-and-figure {
display: table;
margin: 0 auto;
border-spacing: 1em;
}
.code-and-figure > div {
display: table-cell;
vertical-align: middle;
}
ol[start="0"] { counter-reset: list -1; }
ol[start="0"],
ol.continue { list-style: none; }
ol[start="0"] > li,
ol.continue > li { position: relative; counter-increment: list; }
ol[start="0"] > li::before,
ol.continue > li::before { content: counter(list) "."; position: absolute; left: -4.5em; width: 4em; text-align: right; }
.compact, .compact li {
margin-top: 0;
margin-bottom: 0;
}
/* Overview catalog example */
#overview-example {
display:table;
margin: 0 auto 1em;
border-spacing: .5em 0;
min-width: 672px;
}
#overview-example > .col {
display: table-column;
background: hsl(60,100%,90%);
}
#overview-example > .desc {
display: table-cell;
vertical-align: top;
width: 300px;
padding: 1em 1em 0;
text-align: left;
border: thick solid hsl(60,80%,50%);
border-radius: 1em 1em 0 0;
border-bottom: none;
}
#overview-example > .desc > img {
margin: 0 auto;
display: block;
}
#overview-example > .desc > h1 {
background: transparent;
}
#overview-example > .buttons {
display: table-row;
}
#overview-example > .buttons > div {
display: table-cell;
border: thick solid hsl(60,80%,50%);
border-radius: 0 0 1em 1em;
border-top: none;
text-align: center;
}
#overview-example button {
background-color: hsl(120,100%,40%);
border: medium inset hsl(120,70%,40%);
border-radius: 1em;
padding: .5em;
font-weight: bold;
color: white;
font-size: 1.6em;
cursor: pointer;
width: 90%;
margin: 1em auto;
}
/* Visibility: Collapse example */
#visibility-collapse-example {
display: table;
width: 100%;
box-shadow: 3px 3px 10px #333;
}
#visibility-collapse-example > article,
#visibility-collapse-example > nav {
display: table-cell;
}
#visibility-collapse-example > article {
width: 100%;
background: white;
}
#visibility-collapse-example ul,
#visibility-collapse-example li {
list-style: none;
margin: 0;
padding: 0;
}
#visibility-collapse-example > nav > ul {
background: #444;
border-radius: 0.5em;
padding: 0.075em;
}
#visibility-collapse-example li {
padding: 0 0.5em;
background: #ddd;
color: black;
border-radius: 0.40em;
border: #444 solid 0.075em;
}
#visibility-collapse-example li li {
background: #444;
color: white;
margin: 0 -0.5em;
border-radius: 0;
}
#visibility-collapse-example li li:first-child {
border-radius: 0.375em 0.375em 0 0;
}
#visibility-collapse-example a {
background: transparent;
color: inherit;
}
#visibility-collapse-example > nav > ul > li:target,
#visibility-collapse-example > nav > ul > li:hover {
background: #888;
color: white;
}
#visibility-collapse-example > nav > ul > li:not(:target):not(:hover) > ul {
height: 0;
overflow: hidden;
}
#auto-bar {
overflow: hidden;
padding: .25em 1em;
background: #ddd;
list-style: none;
margin: 0;
border-radius: .3em;
}
#auto-bar > li {
float: left;
color: black;
margin: 0;
}
#auto-bar > li:first-child:after,
#auto-bar > li:first-child + li:after {
content: " | ";
white-space: pre;
}
#auto-bar > li > a {
display: inline-block;
padding: 0 .25em;
border-radius: .3em;
}
#auto-bar > li > a:not(:hover):not(:focus) {
text-decoration: none;
}
#auto-bar > li > a:hover {
color: #ddd;
background: #444;
}
#auto-bar > #login { float: right; }
.cross-auto-figure > div {
margin: 0 auto;
width: 70px;
background: #888;
padding: 0 .5em;
border-radius: 1em;
border: 1px solid transparent;
}
.cross-auto-figure > div > div {
border-spacing: 0;
display: table;
background: #ddd;
color: black;
text-align: center;
margin: .5em auto;
padding: .5em;
border-radius: .5em;
}
.axis { color: hsl( 0,80%,40%); }
.side { color: hsl(240,80%,50%); }
.size { color: hsl(120,80%,30%); }
</style>
<style>.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #708090 } /* Comment */
.highlight .k { color: #990055 } /* Keyword */
.highlight .l { color: #669900 } /* Literal */
.highlight .n { color: #0077aa } /* Name */
.highlight .o { color: #999999 } /* Operator */
.highlight .p { color: #999999 } /* Punctuation */
.highlight .cm { color: #708090 } /* Comment.Multiline */
.highlight .cp { color: #708090 } /* Comment.Preproc */
.highlight .c1 { color: #708090 } /* Comment.Single */
.highlight .cs { color: #708090 } /* Comment.Special */
.highlight .kc { color: #990055 } /* Keyword.Constant */
.highlight .kd { color: #990055 } /* Keyword.Declaration */
.highlight .kn { color: #990055 } /* Keyword.Namespace */
.highlight .kp { color: #990055 } /* Keyword.Pseudo */
.highlight .kr { color: #990055 } /* Keyword.Reserved */
.highlight .kt { color: #990055 } /* Keyword.Type */
.highlight .ld { color: #669900 } /* Literal.Date */
.highlight .m { color: #990055 } /* Literal.Number */
.highlight .s { color: #669900 } /* Literal.String */
.highlight .na { color: #0077aa } /* Name.Attribute */
.highlight .nc { color: #0077aa } /* Name.Class */
.highlight .no { color: #0077aa } /* Name.Constant */
.highlight .nd { color: #0077aa } /* Name.Decorator */
.highlight .ni { color: #0077aa } /* Name.Entity */
.highlight .ne { color: #0077aa } /* Name.Exception */
.highlight .nf { color: #0077aa } /* Name.Function */
.highlight .nl { color: #0077aa } /* Name.Label */
.highlight .nn { color: #0077aa } /* Name.Namespace */
.highlight .py { color: #0077aa } /* Name.Property */
.highlight .nt { color: #0077aa } /* Name.Tag */
.highlight .nv { color: #0077aa } /* Name.Variable */
.highlight .ow { color: #999999 } /* Operator.Word */
.highlight .mb { color: #990055 } /* Literal.Number.Bin */
.highlight .mf { color: #990055 } /* Literal.Number.Float */
.highlight .mh { color: #990055 } /* Literal.Number.Hex */
.highlight .mi { color: #990055 } /* Literal.Number.Integer */
.highlight .mo { color: #990055 } /* Literal.Number.Oct */
.highlight .sb { color: #669900 } /* Literal.String.Backtick */
.highlight .sc { color: #669900 } /* Literal.String.Char */
.highlight .sd { color: #669900 } /* Literal.String.Doc */
.highlight .s2 { color: #669900 } /* Literal.String.Double */
.highlight .se { color: #669900 } /* Literal.String.Escape */
.highlight .sh { color: #669900 } /* Literal.String.Heredoc */
.highlight .si { color: #669900 } /* Literal.String.Interpol */
.highlight .sx { color: #669900 } /* Literal.String.Other */
.highlight .sr { color: #669900 } /* Literal.String.Regex */
.highlight .s1 { color: #669900 } /* Literal.String.Single */
.highlight .ss { color: #669900 } /* Literal.String.Symbol */
.highlight .vc { color: #0077aa } /* Name.Variable.Class */
.highlight .vg { color: #0077aa } /* Name.Variable.Global */
.highlight .vi { color: #0077aa } /* Name.Variable.Instance */
.highlight .il { color: #990055 } /* Literal.Number.Integer.Long */
.highlight { background: hsl(24, 20%, 95%); }
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
</style>
</head>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="http://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/Icons/w3c_home" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">CSS Flexible Box Layout Module Level 1</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2015-09-14">14 September 2015</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="http://dev.w3.org/csswg/css-flexbox/">http://dev.w3.org/csswg/css-flexbox/</a>
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/css-flexbox-1/">http://www.w3.org/TR/css-flexbox-1/</a>
<dt>Previous Versions:
<dd><a href="http://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/" rel="previous">http://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/</a>
<dd><a href="http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/" rel="previous">http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/</a>
<dd><a href="http://www.w3.org/TR/2012/WD-css3-flexbox-20120612/" rel="previous">http://www.w3.org/TR/2012/WD-css3-flexbox-20120612/</a>
<dd><a href="http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/" rel="previous">http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/</a>
<dd><a href="http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/" rel="previous">http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/</a>
<dd><a href="http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/" rel="previous">http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/</a>
<dd><a href="http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/" rel="previous">http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/</a>
<dt>Feedback:
<dd><span><a href="mailto:www-style@w3.org?subject=%5Bcss-flexbox%5D%20YOUR%20TOPIC%20HERE">www-style@w3.org</a> with subject line “<kbd>[css-flexbox] <var>… message topic …</var></kbd>” (<a href="http://lists.w3.org/Archives/Public/www-style/" rel="discussion">archives</a>)</span>
<dt>Test Suite:
<dd><a href="http://test.csswg.org/suites/css-flexbox-1_dev/nightly-unstable/">http://test.csswg.org/suites/css-flexbox-1_dev/nightly-unstable/</a>
<dt>Issue Tracking:
<dd><a href="https://github.com/w3c/csswg-drafts/issues/">GitHub</a>
<dt class="editor">Editors:
<dd class="editor p-author h-card vcard"><a class="p-name fn u-url url" href="http://xanthir.com/contact/">Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)
<dd class="editor p-author h-card vcard"><a class="p-name fn u-url url" href="http://fantasai.inkedblade.net/contact">Elika J. Etemad / fantasai</a> (<span class="p-org org">Invited Expert</span>)
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:ratan@microsoft.com">Rossen Atanassov</a> (<span class="p-org org">Microsoft</span>)
<dt>Former Editors:
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:alexmog@microsoft.com">Alex Mogilevsky</a> (<span class="p-org org">Microsoft Corporation</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:dbaron@dbaron.org">L. David Baron</a> (<span class="p-org org">Mozilla Corporation</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:enndeakin@gmail.com">Neil Deakin</a> (<span class="p-org org">Mozilla Corporation</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:ian@hixie.ch">Ian Hickson</a> (<span class="p-org org">formerly of Opera Software</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:hyatt@apple.com">David Hyatt</a> (<span class="p-org org">formerly of Netscape Corporation</span>)
<dt>Issues List:
<dd><span><a href="http://dev.w3.org/csswg/css-flexbox-1/issues-lc-20140925">http://dev.w3.org/csswg/css-flexbox-1/issues-lc-20140925</a></span>
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2015 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply. </p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<div class="p-summary" data-fill-with="abstract">
<p>The specification describes a CSS box model optimized for user interface design. In the flex layout model, the children of a flex container can be laid out in any direction, and can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated. Nesting of these boxes (horizontal inside vertical, or vertical inside horizontal) can be used to build layouts in two dimensions.</p>
<a href="http://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.
</div>
<h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
<div data-fill-with="status">
<p> This is a public copy of the editors’ draft.
It is provided for discussion only and may change at any moment.
Its publication here does not imply endorsement of its contents by W3C.
Don’t cite this document other than as work in progress. </p>
<p> The (<a href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public mailing list <a href="mailto:www-style@w3.org?Subject=%5Bcss-flexbox%5D%20PUT%20SUBJECT%20HERE">www-style@w3.org</a> (see <a href="http://www.w3.org/Mail/Request">instructions</a>)
is preferred for discussion of this specification.
When sending e-mail,
please put the text “css-flexbox” in the subject,
preferably like this:
“[css-flexbox] <em>…summary of comment…</em>” </p>
<p> This document was produced by the <a href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of the <a href="http://www.w3.org/Style/">Style Activity</a>). </p>
<p> This document was produced by a group operating under
the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/32061/status" rel="disclosure">public list of any patent disclosures</a> made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>. </p>
<p> This document is governed by the <a href="http://www.w3.org/2014/Process-20140801/" id="w3c_process_revision">1 August 2014 W3C Process Document</a>. </p>
<p></p>
</div>
<div data-fill-with="at-risk"></div>
<h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="content">Table of Contents</span></h2>
<div data-fill-with="table-of-contents" role="navigation">
<ul class="toc" role="directory">
<li>
<a href="#intro"><span class="secno">1</span> <span class="content"> Introduction</span></a>
<ul class="toc">
<li><a href="#overview"><span class="secno">1.1</span> <span class="content"> Overview</span></a>
<li><a href="#placement"><span class="secno">1.2</span> <span class="content"> Module interactions</span></a>
</ul>
<li><a href="#box-model"><span class="secno">2</span> <span class="content"> Flex Layout Box Model and Terminology</span></a>
<li><a href="#flex-containers"><span class="secno">3</span> <span class="content"> Flex Containers: the <span class="css">flex</span> and <span class="css">inline-flex</span> <span class="property">display</span> values</span></a>
<li>
<a href="#flex-items"><span class="secno">4</span> <span class="content"> Flex Items</span></a>
<ul class="toc">
<li><a href="#abspos-items"><span class="secno">4.1</span> <span class="content"> Absolutely-Positioned Flex Children</span></a>
<li><a href="#item-margins"><span class="secno">4.2</span> <span class="content"> Flex Item Margins and Paddings</span></a>
<li><a href="#painting"><span class="secno">4.3</span> <span class="content"> Flex Item Z-Ordering</span></a>
<li><a href="#visibility-collapse"><span class="secno">4.4</span> <span class="content"> Collapsed Items</span></a>
<li><a href="#min-size-auto"><span class="secno">4.5</span> <span class="content"> Implied Minimum Size of Flex Items</span></a>
</ul>
<li>
<a href="#flow-order"><span class="secno">5</span> <span class="content"> Ordering and Orientation</span></a>
<ul class="toc">
<li><a href="#flex-direction-property"><span class="secno">5.1</span> <span class="content"> Flex Flow Direction: the <span class="property">flex-direction</span> property</span></a>
<li><a href="#flex-wrap-property"><span class="secno">5.2</span> <span class="content"> Flex Line Wrapping: the <span class="property">flex-wrap</span> property</span></a>
<li><a href="#flex-flow-property"><span class="secno">5.3</span> <span class="content"> Flex Direction and Wrap: the <span class="property">flex-flow</span> shorthand</span></a>
<li>
<a href="#order-property"><span class="secno">5.4</span> <span class="content"> Display Order: the <span class="property">order</span> property</span></a>
<ul class="toc">
<li><a href="#order-accessibility"><span class="secno">5.4.1</span> <span class="content"> Reordering and Accessibility</span></a>
</ul>
</ul>
<li><a href="#flex-lines"><span class="secno">6</span> <span class="content"> Flex Lines</span></a>
<li>
<a href="#flexibility"><span class="secno">7</span> <span class="content"> Flexibility</span></a>
<ul class="toc">
<li>
<a href="#flex-property"><span class="secno">7.1</span> <span class="content"> The <span class="property">flex</span> Shorthand</span></a>
<ul class="toc">
<li><a href="#flex-common"><span class="secno">7.1.1</span> <span class="content"> Basic Values of <span class="property">flex</span></span></a>
</ul>
<li>
<a href="#flex-components"><span class="secno">7.2</span> <span class="content"> Components of Flexibility</span></a>
<ul class="toc">
<li><a href="#flex-grow-property"><span class="secno">7.2.1</span> <span class="content"> The <span class="property">flex-grow</span> property</span></a>
<li><a href="#flex-shrink-property"><span class="secno">7.2.2</span> <span class="content"> The <span class="property">flex-shrink</span> property</span></a>
<li><a href="#flex-basis-property"><span class="secno">7.2.3</span> <span class="content"> The <span class="property">flex-basis</span> property</span></a>
</ul>
</ul>
<li>
<a href="#alignment"><span class="secno">8</span> <span class="content"> Alignment</span></a>
<ul class="toc">
<li><a href="#auto-margins"><span class="secno">8.1</span> <span class="content"> Aligning with <span>auto</span> margins</span></a>
<li><a href="#justify-content-property"><span class="secno">8.2</span> <span class="content"> Axis Alignment: the <span class="property">justify-content</span> property</span></a>
<li><a href="#align-items-property"><span class="secno">8.3</span> <span class="content"> Cross-axis Alignment: the <span class="property">align-items</span> and <span class="property">align-self</span> properties</span></a>
<li><a href="#align-content-property"><span class="secno">8.4</span> <span class="content"> Packing Flex Lines: the <span class="property">align-content</span> property</span></a>
<li><a href="#flex-baselines"><span class="secno">8.5</span> <span class="content"> Flex Baselines</span></a>
</ul>
<li>
<a href="#layout-algorithm"><span class="secno">9</span> <span class="content"> Flex Layout Algorithm</span></a>
<ul class="toc">
<li><a href="#box-manip"><span class="secno">9.1</span> <span class="content"> Initial Setup</span></a>
<li><a href="#line-sizing"><span class="secno">9.2</span> <span class="content"> Line Length Determination</span></a>
<li><a href="#main-sizing"><span class="secno">9.3</span> <span class="content"> Main Size Determination</span></a>
<li><a href="#cross-sizing"><span class="secno">9.4</span> <span class="content"> Cross Size Determination</span></a>
<li><a href="#main-alignment"><span class="secno">9.5</span> <span class="content"> Main-Axis Alignment</span></a>
<li><a href="#cross-alignment"><span class="secno">9.6</span> <span class="content"> Cross-Axis Alignment</span></a>
<li><a href="#resolve-flexible-lengths"><span class="secno">9.7</span> <span class="content"> Resolving Flexible Lengths</span></a>
<li><a href="#definite-sizes"><span class="secno">9.8</span> <span class="content"> Definite and Indefinite Sizes</span></a>
<li><a href="#intrinsic-sizes"><span class="secno">9.9</span> <span class="content"> Intrinsic Sizes</span></a>
</ul>
<li>
<a href="#pagination"><span class="secno">10</span> <span class="content"> Fragmenting Flex Layout</span></a>
<ul class="toc">
<li><a href="#pagination-algo"><span class="secno">10.1</span> <span class="content"> Sample Flex Fragmentation Algorithm</span></a>
</ul>
<li><a href="#axis-mapping"><span class="secno"></span> <span class="content"> Appendix A: Axis Mappings</span></a>
<li><a href="#acknowledgments"><span class="secno"></span> <span class="content">Acknowledgments</span></a>
<li>
<a href="#changes"><span class="secno"></span> <span class="content">Changes</span></a>
<ul class="toc">
<li>
<a href="#changes-201505"><span class="secno"></span> <span class="content"> Changes since the 14 May 2015 LCWD</span></a>
<ul class="toc">
<li><a href="#change-201505-substantive"><span class="secno"></span> <span class="content"> Substantive Changes and Bugfixes</span></a>
<li><a href="#change-201505-clarify"><span class="secno"></span> <span class="content"> Clarifications</span></a>
</ul>
<li>
<a href="#changes-201409"><span class="secno"></span> <span class="content"> Changes since the 25 September 2014 LCWD</span></a>
<ul class="toc">
<li><a href="#change-201409-substantive"><span class="secno"></span> <span class="content"> Substantive Changes and Bugfixes</span></a>
<li><a href="#change-201409-clarify"><span class="secno"></span> <span class="content"> Clarifications</span></a>
</ul>
<li>
<a href="#changes-201403"><span class="secno"></span> <span class="content"> Changes since the 25 March 2014 LCWD</span></a>
<ul class="toc">
<li><a href="#change-201403-substantive"><span class="secno"></span> <span class="content"> Substantive Changes and Bugfixes</span></a>
<li><a href="#change-201403-clarify"><span class="secno"></span> <span class="content"> Clarifications</span></a>
</ul>
<li>
<a href="#changes-2012"><span class="secno"></span> <span class="content"> Changes since the 18 September 2012 Candidate Recommendation</span></a>
<ul class="toc">
<li><a href="#changes-2014-substantive"><span class="secno"></span> <span class="content"> Substantive Changes and Bugfixes</span></a>
<li><a href="#changes-2014-clarify"><span class="secno"></span> <span class="content"> Clarifications</span></a>
</ul>
</ul>
<li>
<a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
<ul class="toc">
<li><a href="#conventions"><span class="secno"></span> <span class="content"> Document conventions</span></a>
<li><a href="#conformance-classes"><span class="secno"></span> <span class="content"> Conformance classes</span></a>
<li><a href="#partial"><span class="secno"></span> <span class="content"> Partial implementations</span></a>
<li><a href="#experimental"><span class="secno"></span> <span class="content"> Experimental implementations</span></a>
<li><a href="#testing"><span class="secno"></span> <span class="content"> Non-experimental implementations</span></a>
</ul>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ul class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
</ul>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ul class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
</ul>
<li><a href="#property-index"><span class="secno"></span> <span class="content">Property Index</span></a>
</ul>
</div>
<main>
<h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content"> Introduction</span><a class="self-link" href="#intro"></a></h2>
<p><em>This section is not normative.</em></p>
<p>CSS 2.1 defined four layout modes — algorithms which determine
the size and position of boxes based on their relationships
with their sibling and ancestor boxes:</p>
<ul>
<li data-md="">
<p>block layout, designed for laying out documents</p>
<li data-md="">
<p>inline layout, designed for laying out text</p>
<li data-md="">
<p>table layout, designed for laying out 2D data in a tabular format</p>
<li data-md="">
<p>positioned layout, designed for very explicit positioning without much regard for other elements in the document</p>
</ul>
<p>This module introduces a new layout mode, <dfn data-dfn-type="dfn" data-export="" id="flex-layout">flex layout<a class="self-link" href="#flex-layout"></a></dfn>,
which is designed for laying out more complex applications and webpages.</p>
<h3 class="heading settled" data-level="1.1" id="overview"><span class="secno">1.1. </span><span class="content"> Overview</span><a class="self-link" href="#overview"></a></h3>
<p><em>This section is not normative.</em></p>
<p>Flex layout is superficially similar to block layout.
It lacks many of the more complex text- or document-centric properties
that can be used in block layout, such as <a href="http://www.w3.org/TR/CSS2/visuren.html#floats">floats</a> and <a href="http://www.w3.org/TR/css3-multicol/">columns</a>.
In return it gains simple and powerful tools
for distributing space and aligning content
in ways that web apps and complex web pages often need.
The contents of a flex container:</p>
<ul>
<li data-md="">
<p>can be laid out in any <a href="#flex-direction-property">flow direction</a> (leftwards, rightwards, downwards, or even upwards!)</p>
<li data-md="">
<p>can have their display order <a class="css" data-link-type="value" href="#valdef-flex-direction-row-reverse">reversed</a> or <a href="#order-property">rearranged</a> at the style layer
(i.e., visual order can be independent of source and speech order)</p>
<li data-md="">
<p>can be laid out linearly along a single (<a data-link-type="dfn" href="#main-axis">main</a>) axis or <a href="#flex-wrap-property">wrapped</a> into multiple lines along a secondary (<a data-link-type="dfn" href="#cross-axis">cross</a>) axis</p>
<li data-md="">
<p>can <a href="#flexibility">“flex” their sizes</a> to respond to the available space</p>
<li data-md="">
<p>can be <a href="#alignment">aligned</a> with respect to their container or each other on the secondary (<a data-link-type="dfn" href="#cross-axis">cross</a>)</p>
<li data-md="">
<p>can be dynamically <a href="#visibility-collapse">collapsed</a> or uncollapsed
along the <a data-link-type="dfn" href="#main-axis">main axis</a> while preserving the container’s <a data-link-type="dfn" href="#cross-size">cross size</a></p>
</ul>
<div class="example" id="example-ede42902">
<a class="self-link" href="#example-ede42902"></a> Here’s an example of a catalog where each item has a title, a photo, a description, and a purchase button.
The designer’s intention is that each entry has the same overall size,
that the photo be above the text,
and that the purchase buttons aligned at the bottom, regardless of the length of the item’s description.
Flex layout makes many aspects of this design easy:
<ul>
<li data-md="">
<p>The catalog uses flex layout to lay out rows of items horizontally,
and to ensure that items within a row are all equal-height.
Each entry is then itself a column flex container,
laying out its contents vertically.</p>
<li data-md="">
<p>Within each entry, the source document content is ordered logically
with the title first, followed by the description and the photo.
This provides a sensible ordering for speech rendering and in non-CSS browsers.
For a more compelling visual presentation, however, <a class="property" data-link-type="propdesc" href="#propdef-order">order</a> is used to pull the image up from later in the content to the top,
and <a class="property" data-link-type="propdesc" href="#propdef-align-self">align-self</a> is used to center it horizontally.</p>
<li data-md="">
<p>An <a href="#auto-margins"><span class="css">auto</span> margin</a> above the purchase button
forces it to the bottom within each entry box,
regardless of the height of that item’s description.</p>
<pre class="lang-css">#deals {
display: flex; /* Flex layout so items <a data-link-type="property" href="#propdef-align-self">have equal height</a> */
flex-flow: row wrap; /* <a href="#flex-flow-property">Allow items to wrap into multiple lines</a> */
}
.sale-item {
display: flex; /* Lay out each item using flex layout */
flex-flow: column; /* <a href="#flex-flow-property">Lay out item’s contents vertically</a> */
}
.sale-item > img {
order: -1; /* <a href="#order-property">Shift image before other content (in visual order)</a> */
align-self: center; /* <a data-link-type="property" href="#propdef-align-self">Center the image cross-wise (horizontally)</a> */
}
.sale-item > button {
margin-top: auto; /* <a href="#auto-margins">Auto top margin pushes button to bottom</a> */
}
</pre>
<pre class="lang-markup highlight"><span class="nt">&lt;section</span> <span class="na">id=</span><span class="s">"deals"</span><span class="nt">></span>
<span class="nt">&lt;section</span> <span class="na">class=</span><span class="s">"sale-item"</span><span class="nt">></span>
<span class="nt">&lt;h1></span>Computer Starter Kit<span class="nt">&lt;/h1></span>
<span class="nt">&lt;p></span>This is the best computer money can buy, if you don’t have much money.
<span class="nt">&lt;ul></span>
<span class="nt">&lt;li></span>Computer
<span class="nt">&lt;li></span>Monitor
<span class="nt">&lt;li></span>Keyboard
<span class="nt">&lt;li></span>Mouse
<span class="nt">&lt;/ul></span>
<span class="nt">&lt;img</span> <span class="na">src=</span><span class="s">"images/computer.jpg"</span>
<span class="na">alt=</span><span class="s">"You get: a white computer with matching peripherals."</span><span class="nt">></span>
<span class="nt">&lt;button></span>BUY NOW<span class="nt">&lt;/button></span>
<span class="nt">&lt;/section></span>
<span class="nt">&lt;section</span> <span class="na">class=</span><span class="s">"sale-item"</span><span class="nt">></span>
<span class="nt">&lt;/section></span>
<span class="nt">&lt;/section></span></pre>
</ul>
<figure>
<div id="overview-example">
<div class="col"></div>
<div class="col"></div>
<div class="desc">
<img alt="You get: a white computer with matching keyboard and monitor." src="images/computer.jpg">
<h1 id="quiet-pubrules-1" style="font-size: 1.4em;">Computer Starter Kit</h1>
<p> This is the best computer money can buy,
if you don’t have much money. </p>
<ul>
<li>Computer
<li>Monitor
<li>Keyboard
<li>Mouse
</ul>
</div>
<div class="desc">
<img alt="You get: beautiful ASCII art." src="images/printer.png">
<h1 id="quiet-pubrules-2" style="font-size: 1.4em;">Printer</h1>
<p> Only capable of printing
ASCII art. </p>
<ul>
<li>Paper and ink not included.
</ul>
</div>
<div class="buttons">
<div>
<button>BUY NOW</button>
</div>
<div>
<button>BUY NOW</button>
</div>
</div>
</div>
<figcaption> An example rendering of the code above. </figcaption>
</figure>
</div>
<h3 class="heading settled" data-level="1.2" id="placement"><span class="secno">1.2. </span><span class="content"> Module interactions</span><a class="self-link" href="#placement"></a></h3>
<p>This module extends the definition of the <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> property <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a>,
adding a new block-level and new inline-level display type,
and defining a new type of formatting context
along with properties to control its layout.
None of the properties defined in this module apply to the <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-pseudo-4/#selectordef-first-line">::first-line</a> or <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-pseudo-4/#selectordef-first-letter">::first-letter</a> pseudo-elements.</p>
<h2 class="heading settled" data-level="2" id="box-model"><span class="secno">2. </span><span class="content"> Flex Layout Box Model and Terminology</span><a class="self-link" href="#box-model"></a></h2>
<p>A <dfn data-dfn-type="dfn" data-export="" id="flex-container">flex container<a class="self-link" href="#flex-container"></a></dfn> is the box generated by an element with a
computed <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> of <a class="css" data-link-type="maybe" href="#valdef-display-flex">flex</a> or <a class="css" data-link-type="maybe" href="#valdef-display-inline-flex">inline-flex</a>.
In-flow children of a flex container are called <dfn data-dfn-type="dfn" data-export="" data-lt="flex item" id="flex-item">flex items<a class="self-link" href="#flex-item"></a></dfn> and are laid out using the flex layout model.</p>
<p>Unlike block and inline layout,
whose layout calculations are biased to the <a href="http://www.w3.org/TR/css3-writing-modes/#abstract-box">block and inline flow directions</a>,
flex layout is biased to the <dfn data-dfn-type="dfn" data-lt="flex direction" data-noexport="" id="flex-direction">flex directions<a class="self-link" href="#flex-direction"></a></dfn>.
To make it easier to talk about flex layout,
this section defines a set of flex flow–relative terms.
The <a class="property" data-link-type="propdesc" href="#propdef-flex-flow">flex-flow</a> value and the <a data-link-type="dfn" href="https://drafts.csswg.org/css-writing-modes-3/#writing-mode">writing mode</a> determine how these terms map
to physical directions (top/right/bottom/left),
axes (vertical/horizontal), and sizes (width/height).</p>
<figure>
<img alt="" height="277" src="images/flex-direction-terms.svg" width="665">
<figcaption> An illustration of the various directions and sizing terms as applied to a <a class="css" data-link-type="maybe" href="#valdef-flex-direction-row">row</a> flex container. </figcaption>
</figure>
<dl id="main">
<dt class="axis">main axis
<dt class="axis">main dimension
<dd> The <dfn data-dfn-type="dfn" data-export="" data-lt="main axis|main-axis" id="main-axis">main axis<a class="self-link" href="#main-axis"></a></dfn> of a flex container is the primary axis along which <a data-link-type="dfn" href="#flex-item">flex items</a> are laid out.
It extends in the <dfn data-dfn-type="dfn" data-export="" id="main-dimension">main dimension<a class="self-link" href="#main-dimension"></a></dfn>.
<dt class="side">main-start
<dt class="side">main-end
<dd> The <a data-link-type="dfn" href="#flex-item">flex items</a> are placed within the container
starting on the <dfn data-dfn-type="dfn" data-export="" id="main-start">main-start<a class="self-link" href="#main-start"></a></dfn> side
and going toward the <dfn data-dfn-type="dfn" data-export="" id="main-end">main-end<a class="self-link" href="#main-end"></a></dfn> side.
<dt class="size">main size
<dt class="size">main size property
<dd> A <a data-link-type="dfn" href="#flex-item">flex item</a>’s width or height,
whichever is in the <a data-link-type="dfn" href="#main-dimension">main dimension</a>,
is the item’s <dfn data-dfn-type="dfn" data-export="" id="main-size">main size<a class="self-link" href="#main-size"></a></dfn>.
The <a data-link-type="dfn" href="#flex-item">flex item</a>’s <dfn data-dfn-type="dfn" data-export="" data-lt="main size property|max main size property|min main size property" id="main-size-property">main size property<a class="self-link" href="#main-size-property"></a></dfn> is
either the <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-width">width</a> or <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-height">height</a> property,
whichever is in the <a data-link-type="dfn" href="#main-dimension">main dimension</a>.
</dl>
<dl id="cross">
<dt class="axis">cross axis
<dt class="axis">cross dimension
<dd> The axis perpendicular to the <a data-link-type="dfn" href="#main-axis">main axis</a> is called the <dfn data-dfn-type="dfn" data-export="" data-lt="cross axis|cross-axis" id="cross-axis">cross axis<a class="self-link" href="#cross-axis"></a></dfn>.
It extends in the <dfn data-dfn-type="dfn" data-export="" id="cross-dimension">cross dimension<a class="self-link" href="#cross-dimension"></a></dfn>.
<dt class="side">cross-start
<dt class="side">cross-end
<dd> <a data-link-type="dfn" href="#flex-line">Flex lines</a> are filled with items and placed into the container
starting on the <dfn data-dfn-type="dfn" data-export="" id="cross-start">cross-start<a class="self-link" href="#cross-start"></a></dfn> side of the flex container
and going toward the <dfn data-dfn-type="dfn" data-export="" id="cross-end">cross-end<a class="self-link" href="#cross-end"></a></dfn> side.
<dt class="size">cross size
<dt class="size">cross size property
<dd> The width or height of a <a data-link-type="dfn" href="#flex-item">flex item</a>,
whichever is in the <a data-link-type="dfn" href="#cross-dimension">cross dimension</a>,
is the item’s <dfn data-dfn-type="dfn" data-export="" id="cross-size">cross size<a class="self-link" href="#cross-size"></a></dfn>.
The <dfn data-dfn-type="dfn" data-export="" data-lt="cross size property|max cross size property|min cross size property" id="cross-size-property">cross size property<a class="self-link" href="#cross-size-property"></a></dfn> is
whichever of <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-width">width</a> or <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-height">height</a> that is in the <a data-link-type="dfn" href="#cross-dimension">cross dimension</a>.
</dl>
<h2 class="heading settled" data-level="3" id="flex-containers"><span class="secno">3. </span><span class="content"> Flex Containers: the <a class="css" data-link-type="maybe" href="#valdef-display-flex">flex</a> and <a class="css" data-link-type="maybe" href="#valdef-display-inline-flex">inline-flex</a> <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> values</span><a class="self-link" href="#flex-containers"></a></h2>
<table class="definition propdef partial" data-link-for-hint="display">
<tbody>
<tr>
<th>Name:
<td><a class="css" data-link-type="property" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a>
<tr class="value">
<th>New values:
<td class="prod">flex <a data-link-type="grammar" href="https://drafts.csswg.org/css-values-3/#comb-one">|</a> inline-flex
</table>
<dl>
<dt><dfn class="css" data-dfn-for="display" data-dfn-type="value" data-export="" id="valdef-display-flex">flex<a class="self-link" href="#valdef-display-flex"></a></dfn>
<dd> This value causes an element to generate a block-level <a data-link-type="dfn" href="#flex-container">flex container</a> box.
<dt><dfn class="css" data-dfn-for="display" data-dfn-type="value" data-export="" id="valdef-display-inline-flex">inline-flex<a class="self-link" href="#valdef-display-inline-flex"></a></dfn>
<dd> This value causes an element to generate an inline-level <a data-link-type="dfn" href="#flex-container">flex container</a> box.
</dl>
<p>A <a data-link-type="dfn" href="#flex-container">flex container</a> establishes a new <dfn data-dfn-type="dfn" data-export="" id="flex-formatting-context">flex formatting context<a class="self-link" href="#flex-formatting-context"></a></dfn> for its contents.
This is the same as establishing a block formatting context,
except that flex layout is used instead of block layout.
For example, floats do not intrude into the flex container,
and the flex container’s margins do not collapse with the margins of its contents. <a data-link-type="dfn" href="#flex-container">Flex containers</a> form a containing block for their contents <a href="http://www.w3.org/TR/CSS2/visudet.html#containing-block-details">exactly like block containers do</a>. <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a> The <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-overflow-3/#propdef-overflow">overflow</a> property applies to <a data-link-type="dfn" href="#flex-container">flex containers</a>.</p>
<p>Flex containers are not block containers,
and so some properties that were designed with the assumption of block layout don’t apply in the context of flex layout.
In particular:</p>
<ul>
<li data-md="">
<p>the <a class="property" data-link-type="propdesc">column-*</a> properties in the Multi-column Layout module <a data-link-type="biblio" href="#biblio-css3col">[CSS3COL]</a> have no effect on a flex container.</p>
<li data-md="">
<p><a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-float">float</a> and <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-clear">clear</a> do not create floating or clearance of <a data-link-type="dfn" href="#flex-item">flex item</a>,
and do not take it out-of-flow.</p>
<li data-md="">
<p><a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-vertical-align">vertical-align</a> has no effect on a flex item.</p>
<li data-md="">
<p>the <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-pseudo-4/#selectordef-first-line">::first-line</a> and <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-pseudo-4/#selectordef-first-letter">::first-letter</a> pseudo-elements do not apply to <a data-link-type="dfn" href="#flex-container">flex containers</a>,
and <a data-link-type="dfn" href="#flex-container">flex containers</a> do not contribute a <a data-link-type="dfn" href="https://drafts.csswg.org/css-pseudo-4/#first-formatted-line">first formatted line</a> or <a data-link-type="dfn">first letter</a> to their ancestors.</p>
</ul>
<p>If an element’s specified <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> is <a class="css" data-link-type="maybe" href="#valdef-display-inline-flex">inline-flex</a>,
then its <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> property computes to <a class="css" data-link-type="maybe" href="#valdef-display-flex">flex</a> in certain circumstances:
the table in <a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Section 9.7</a> is amended to contain an additional row,
with <a class="css" data-link-type="maybe" href="#valdef-display-inline-flex">inline-flex</a> in the "Specified Value" column
and <a class="css" data-link-type="maybe" href="#valdef-display-flex">flex</a> in the "Computed Value" column.</p>
<h2 class="heading settled" data-level="4" id="flex-items"><span class="secno">4. </span><span class="content"> Flex Items</span><a class="self-link" href="#flex-items"></a></h2>
<p>Loosely speaking, the <a data-link-type="dfn" href="#flex-item">flex items</a> of a <a data-link-type="dfn" href="#flex-container">flex container</a> are boxes representing its in-flow contents.</p>
<p>Each in-flow child of a <a data-link-type="dfn" href="#flex-container">flex container</a> becomes a <a data-link-type="dfn" href="#flex-item">flex item</a>,
and each contiguous run of text that is directly contained inside a <a data-link-type="dfn" href="#flex-container">flex container</a> is wrapped in an anonymous <a data-link-type="dfn" href="#flex-item">flex item</a>.
However, an anonymous flex item that contains only <a href="http://www.w3.org/TR/CSS2/text.html#white-space-prop">white space</a> (i.e. characters that can be affected by the <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-text-3/#propdef-white-space">white-space</a> property)
is not rendered (just as if it were <span class="css">display:none</span>).</p>
<div class="example" id="example-08a64279">
<a class="self-link" href="#example-08a64279"></a>
<p>Examples of flex items: </p>
<pre class="lang-markup">&lt;div style="display:flex">
&lt;!-- flex item: block child -->
&lt;div id="item1">block&lt;/div>
&lt;!-- flex item: floated element; floating is ignored -->
&lt;div id="item2" style="float: left;">float&lt;/div>
&lt;!-- flex item: anonymous block box around inline content -->
anonymous item 3
&lt;!-- flex item: inline child -->
&lt;span>
item 4
&lt;!-- flex items do not <a href="http://www.w3.org/TR/CSS2/visuren.html#anonymous-block-level">split</a> around blocks -->
&lt;q style="display: block" id=not-an-item>item 4&lt;/q>
item 4
&lt;/span>
&lt;/div>
</pre>
<figure>
<figcaption>Flex items determined from above code block</figcaption>
<a href="examples/flex-item-determination.html"> <object data="images/flex-item-determination.png" type="image/png"> <ol> <li>Flex item containing <samp>block</samp>. </li><li>Flex item containing <samp>float</samp>. </li><li>(Anonymous, unstyleable) flex item containing <samp>anonymous item 3</samp>. </li><li>Flex item containing three blocks in succession: <ul> <li>Anonymous block containing <samp>item 4</samp>. </li><li><code>&lt;q></code> element block containing <samp>item 4</samp>. </li><li>Anonymous block containing <samp>item 4</samp>. </li></ul> </li></ol> </object> </a>
</figure>
<p>Note that the inter-element white space disappears:
it does not become its own flex item,
even though the inter-element text <em>does</em> get wrapped in an anonymous flex item.</p>
<p>Note also that the anonymous item’s box is unstyleable,
since there is no element to assign style rules to.
Its contents will however inherit styles (such as font settings) from the flex container.</p>
</div>
<p>A <a data-link-type="dfn" href="#flex-item">flex item</a> establishes a new formatting context for its contents.
The type of this formatting context is determined by its <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> value, as usual.
However, flex items themselves are <dfn data-dfn-type="dfn" data-noexport="" id="flex-level">flex-level<a class="self-link" href="#flex-level"></a></dfn> boxes, not block-level boxes:
they participate in their container’s flex formatting context,
not in a block formatting context.</p>
<hr>
<p class="note" role="note">Note: Authors reading this spec may want to <a href="#item-margins">skip past the following box-generation and static position details</a>.</p>
<p>The <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> value of a <a data-link-type="dfn" href="#flex-item">flex item</a> is <a data-link-type="dfn" href="https://drafts.csswg.org/css-display-3/#blockify">blockified</a>:
if the specified <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> of an in-flow child of an element generating a <a data-link-type="dfn" href="#flex-container">flex container</a> is an inline-level value, it computes to its block-level equivalent.
(See <a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS2.1§9.7</a> <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a> and <a href="http://www.w3.org/TR/css-display/#transformations">CSS Display</a> <a data-link-type="biblio" href="#biblio-css3-display">[CSS3-DISPLAY]</a> for details on this type of <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> value conversion.)</p>
<p class="note" role="note">Note: Some values of <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display</a> normally trigger the creation of anonymous boxes around the original box.
If such a box is a <a data-link-type="dfn" href="#flex-item">flex item</a>,
it is blockified first,
and so anonymous box creation will not happen.
For example, two contiguous <a data-link-type="dfn" href="#flex-item">flex items</a> with <a class="css" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display: table-cell</a> will become two separate <a class="css" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display: block</a> <a data-link-type="dfn" href="#flex-item">flex items</a>,
instead of being wrapped into a single anonymous table.</p>
<h3 class="heading settled" data-level="4.1" id="abspos-items"><span class="secno">4.1. </span><span class="content"> Absolutely-Positioned Flex Children</span><a class="self-link" href="#abspos-items"></a></h3>
<p>An absolutely-positioned child of a <a data-link-type="dfn" href="#flex-container">flex container</a> does not participate in flex layout.
However, it does participate in the <a href="#algo-flex-order">reordering step</a> (see <a class="property" data-link-type="propdesc" href="#propdef-order">order</a>),
which has an effect on painting order.</p>
<p>The <a href="http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width">static position</a> of an absolutely-positioned child of a <a data-link-type="dfn" href="#flex-container">flex container</a> is determined such that the child is positioned
as if it were the sole <a data-link-type="dfn" href="#flex-item">flex item</a> in the <a data-link-type="dfn" href="#flex-container">flex container</a>,
assuming both the child and the flex container
were fixed-size boxes of their used size.</p>
<div class="example" id="example-5860ae02"><a class="self-link" href="#example-5860ae02"></a> The effect of this is that if you set, for example, <a class="css" data-link-type="propdesc" href="#propdef-align-content">align-content: center;</a> on an absolutely-positioned child of a <a data-link-type="dfn" href="#flex-container">flex container</a>,
the child’s static position will center it in the <a data-link-type="dfn" href="#flex-container">flex container’s</a> <a data-link-type="dfn" href="#cross-axis">cross axis</a>. </div>
<div class="note" role="note"> The <dfn data-dfn-type="dfn" data-noexport="" id="static-position-rectangle">static-position rectangle<a class="self-link" href="#static-position-rectangle"></a></dfn> is the <a data-link-type="dfn" href="https://drafts.csswg.org/css-align-3/#alignment-container">alignment container</a> used to determine the static-position offsets of an absolutely-positioned box.
In block layout it corresponds to the position of the “hypothetical box”
described in <a href="http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width">CSS2.1§10.3.7</a>.
(Since it has no alignment properties,
CSS2.1 always uses a <a data-link-type="dfn" href="https://drafts.csswg.org/css-writing-modes-3/#block-start">block-start</a> <a data-link-type="dfn" href="https://drafts.csswg.org/css-writing-modes-3/#inline-start">inline-start</a> alignment
of the absolutely-positioned box within the <a data-link-type="dfn" href="#static-position-rectangle">static-position rectangle</a>.)
Note that this definition will eventually move to the CSS Positioning module. </div>
<h3 class="heading settled" data-level="4.2" id="item-margins"><span class="secno">4.2. </span><span class="content"> Flex Item Margins and Paddings</span><a class="self-link" href="#item-margins"></a></h3>
<p>The margins of adjacent <a data-link-type="dfn" href="#flex-item">flex items</a> do not <a href="http://www.w3.org/TR/CSS2/box.html#collapsing-margins">collapse</a>.</p>
<p>Percentage margins and paddings on <a data-link-type="dfn" href="#flex-item">flex items</a> are always resolved against their own axis:
left and right margins resolve against the containing’s block width,
and top and bottom margins resolve against the containing block’s height.
Unlike blocks, <a data-link-type="dfn" href="https://drafts.csswg.org/css-writing-modes-3/#block-axis">block-axis</a> margins do not resolve against
the inline dimension of their containing block.</p>
<p>Auto margins expand to absorb extra space in the corresponding dimension.
They can be used for alignment,
or to push adjacent flex items apart.
See <a href="#auto-margins">Aligning with <span class="css">auto</span> margins</a>.</p>
<h3 class="heading settled" data-level="4.3" id="painting"><span class="secno">4.3. </span><span class="content"> Flex Item Z-Ordering</span><a class="self-link" href="#painting"></a></h3>
<p><a data-link-type="dfn" href="#flex-item">Flex items</a> paint exactly the same as inline blocks <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a>,
except that <a class="property" data-link-type="propdesc" href="#propdef-order">order</a>-modified document order is used in place of raw document order,
and <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-position-3/#propdef-z-index">z-index</a> values other than <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-position-3/#valdef-z-index-auto">auto</a> create a stacking context
even if <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-position-3/#propdef-position">position</a> is <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-position-3/#valdef-position-static">static</a>.</p>
<p class="note" role="note">Note: Descendants that are positioned outside a flex item still participate
in any stacking context established by the flex item.</p>
<h3 class="heading settled" data-level="4.4" id="visibility-collapse"><span class="secno">4.4. </span><span class="content"> Collapsed Items</span><a class="self-link" href="#visibility-collapse"></a></h3>
<p>Specifying <span class="css">visibility:collapse</span> on a flex item
causes it to become a <dfn data-dfn-type="dfn" data-local-lt="collapsed" data-noexport="" id="collapsed-flex-item">collapsed flex item<a class="self-link" href="#collapsed-flex-item"></a></dfn>,
producing an effect similar to <span class="css">visibility:collapse</span> on a table-row or table-column:
the collapsed flex item is removed from rendering entirely,
but leaves behind a "strut" that keeps the flex line’s cross-size stable.
Thus, if a flex container has only one flex line,
dynamically collapsing or uncollapsing items
may change the <a data-link-type="dfn" href="#flex-container">flex container</a>’s <a data-link-type="dfn" href="#main-size">main size</a>, but
is guaranteed to have no effect on its <a data-link-type="dfn" href="#cross-size">cross size</a> and won’t cause the rest of the page’s layout to "wobble".
Flex line wrapping <em>is</em> re-done after collapsing, however,
so the cross-size of a flex container with multiple lines might or might not change.</p>
<p>Though collapsed flex items aren’t rendered,
they do appear in the <a href="http://www.w3.org/TR/CSS2/intro.html#formatting-structure">formatting structure</a>.
Therefore, unlike on <span class="css">display:none</span> items <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a>,
effects that depend on a box appearing in the formatting structure
(like incrementing counters or running animations and transitions)
still operate on collapsed items.</p>
<div class="example" id="example-84f3b8fd">
<a class="self-link" href="#example-84f3b8fd"></a> In the following example,
a sidebar is sized to fit its content. <a class="css" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visufx.html#propdef-visibility">visibility: collapse</a> is used to dynamically hide parts of a navigation sidebar
without affecting its width, even though the widest item (“Architecture”)
is in a collapsed section.
<figure>
<figcaption>Sample live rendering for example code below</figcaption>
<div id="visibility-collapse-example">
<nav>
<ul>
<li id="nav-about">
<a href="#nav-about">About</a>
<ul>
<li><a href="#">History</a>
<li><a href="#">Mission</a>
<li><a href="#">People</a>
</ul>
<li id="nav-projects">
<a href="#nav-projects">Projects</a>
<ul>
<li><a href="#">Art</a>
<li><a href="#">Architecture</a>
<li><a href="#">Music</a>
</ul>
<li id="nav-interact">
<a href="#nav-interact">Interact</a>
<ul>
<li><a href="#">Blog</a>
<li><a href="#">Forums</a>
</ul>
</ul>
</nav>
<article> Hover over the menu to the left:
each section expands to show its sub-items.
In order to keep the sidebar width (and this main area width) stable, <a class="css" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visufx.html#propdef-visibility">visibility: collapse</a> is used instead of <a class="css" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visuren.html#propdef-display">display: none</a>.
This results in a sidebar that is always wide enough for the word “Architecture”,
even though it is not always visible. </article>
</div>
</figure>
<pre class="lang-css">@media (min-width: 60em) {
/* <a href="http://www.w3.org/TR/css3-mediaqueries/#width">two column layout only when enough room</a> (relative to default text size) */
div { display: flex; }
#main {
flex: 1; /* <a href="#flexibility">Main takes up all remaining space</a> */
order: 1; /* <a href="#order-property">Place it after (to the right of) the navigation</a> */
min-width: 12em; /* Optimize main content area sizing */
}
}
/* menu items use flex layout so that visibility:collapse will work */
nav > ul > li {
display: flex;
flex-flow: column;
}
/* dynamically collapse submenus when not targetted */
nav > ul > li:not(:target):not(:hover) > ul {
visibility: collapse;
}
</pre>
<pre class="lang-markup highlight"><span class="nt">&lt;div></span>
<span class="nt">&lt;article</span> <span class="na">id=</span><span class="s">"main"</span><span class="nt">></span>
Interesting Stuff to Read
<span class="nt">&lt;/article></span>
<span class="nt">&lt;nav></span>
<span class="nt">&lt;ul></span>
<span class="nt">&lt;li</span> <span class="na">id=</span><span class="s">"nav-about"</span><span class="nt">>&lt;a</span> <span class="na">href=</span><span class="s">"#nav-about"</span><span class="nt">></span>About<span class="nt">&lt;/a></span>
<span class="nt">&lt;li</span> <span class="na">id=</span><span class="s">"nav-projects"</span><span class="nt">>&lt;a</span> <span class="na">href=</span><span class="s">"#nav-projects"</span><span class="nt">></span>Projects<span class="nt">&lt;/a></span>
<span class="nt">&lt;ul></span>
<span class="nt">&lt;li>&lt;a</span> <span class="na">href=</span><span class="s">"…"</span><span class="nt">></span>Art<span class="nt">&lt;/a></span>
<span class="nt">&lt;li>&lt;a</span> <span class="na">href=</span><span class="s">"…"</span><span class="nt">></span>Architecture<span class="nt">&lt;/a></span>
<span class="nt">&lt;li>&lt;a</span> <span class="na">href=</span><span class="s">"…"</span><span class="nt">></span>Music<span class="nt">&lt;/a></span>
<span class="nt">&lt;/ul></span>
<span class="nt">&lt;li</span> <span class="na">id=</span><span class="s">"nav-interact"</span><span class="nt">>&lt;a</span> <span class="na">href=</span><span class="s">"#nav-interact"</span><span class="nt">></span>Interact<span class="nt">&lt;/a></span>
<span class="nt">&lt;/ul></span>
<span class="nt">&lt;/nav></span>
<span class="nt">&lt;/div></span>
<span class="nt">&lt;footer></span>
…</pre>
</div>
<p>To compute the size of the strut, flex layout is first performed with all items uncollapsed,
and then re-run with each collapsed item replaced by a strut that maintains
the original cross-size of the item’s original line.
See the <a href="#layout-algorithm">Flex Layout Algorithm</a> for the normative definition of how <span class="css">visibility:collapse</span> interacts with flex layout.</p>
<p class="note" role="note">Note: Using <span class="css">visibility:collapse</span> on any flex items
will cause the flex layout algorithm to repeat partway through,
re-running the most expensive steps.
It’s recommended that authors continue to use <span class="css">display:none</span> to hide items
if the items will not be dynamically collapsed and uncollapsed,
as that is more efficient for the layout engine.
(Since only part of the steps need to be repeated when <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visufx.html#propdef-visibility">visibility</a> is changed,
however, 'visibility: collapse' is still recommended for dynamic cases.)</p>
<h3 class="heading settled" data-level="4.5" id="min-size-auto"><span class="secno">4.5. </span><span class="content"> Implied Minimum Size of Flex Items</span><a class="self-link" href="#min-size-auto"></a></h3>
<p>To provide a more reasonable default minimum size for <a data-link-type="dfn" href="#flex-item">flex items</a>,
this specification introduces a new <a class="css" data-link-type="maybe" href="#valdef-min-width-auto">auto</a> value
as the initial value of the <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-min-width">min-width</a> and <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css2/visudet.html#propdef-min-height">min-height</a> properties defined in CSS 2.1. <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a></p>
<table class="definition propdef partial" data-link-for-hint="min-width">
<tbody>
<tr>
<th>Name:
<td><a class="css" data-link-type="property" href="https://drafts.csswg.org/css2/visudet.html#propdef-min-width">min-width</a>, <a class="css" data-link-type="property" href="https://drafts.csswg.org/css2/visudet.html#propdef-min-height">min-height</a>
<tr class="value">
<th>New values:
<td class="prod">auto
<tr>
<th>New initial value:
<td>auto
<tr>
<th>New computed value:
<td>the percentage as specified or the absolute length or a keyword
</table>
<dl>
<dt><dfn class="css" data-dfn-for="min-width, min-height" data-dfn-type="value" data-export="" id="valdef-min-width-auto">auto<a class="self-link" href="#valdef-min-width-auto"></a></dfn>
<dd>
On a <a data-link-type="dfn" href="#flex-item">flex item</a> whose <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-overflow-3/#propdef-overflow">overflow</a> is <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-overflow-3/#valdef-overflow-visible">visible</a> in the <a data-link-type="dfn" href="#main-axis">main axis</a>,
when specified on the <a data-link-type="dfn" href="#flex-item">flex item’s</a> main-axis min-size property,
the following table gives the minimum size:
<table class="data">
<colgroup span="2"></colgroup>
<colgroup span="1"></colgroup>
<thead>
<tr>
<th>Specified Size
<th>Transferred Size
<th>Minimum Size
<tbody>
<tr>
<td>
<td>
<td><var>content size</var>
<tr>
<td>✓
<td>
<td>min(<var>specified size</var>, <var>content size</var>)
<tr>
<td>
<td>✓
<td>min(<var>transferred size</var>, <var>content size</var>)
<tr>
<td>✓
<td>✓
<td>min(<var>specified size</var>, <var>content size</var>)
</table>
<p>Where:</p>
<dl>