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

Latest commit

 

History

History
2803 lines (2424 loc) · 105 KB

File metadata and controls

2803 lines (2424 loc) · 105 KB
<h1>CSS Flexible Box Layout Module Level 1</h1>
<pre class='metadata'>
Shortname: css-flexbox
Level: 1
Status: ED
Group: csswg
ED: http://dev.w3.org/csswg/css-flexbox/
TR: http://www.w3.org/TR/css3-flexbox/
Previous Version: http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/
Previous Version: http://www.w3.org/TR/2012/WD-css3-flexbox-20120612/
Previous Version: http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/
Previous Version: http://www.w3.org/TR/2011/WD-css3-flexbox-20111129/
Previous Version: http://www.w3.org/TR/2011/WD-css3-flexbox-20110322/
Previous Version: http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/
Abstract: 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.
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Editor: fantasai, Mozilla, http://fantasai.inkedblade.net/contact
Editor: Rossen Atanassov, Microsoft, ratan@microsoft.com
Former Editor: Alex Mogilevsky, Microsoft Corporation, alexmog@microsoft.com
Former Editor: L. David Baron, Mozilla Corporation, dbaron@dbaron.org
Former Editor: Neil Deakin, Mozilla Corporation, enndeakin@gmail.com
Former Editor: Ian Hickson, formerly of Opera Software, ian@hixie.ch
Former Editor: David Hyatt, formerly of Netscape Corporation, hyatt@apple.com
Test Suite: http://test.csswg.org/suites/css3-flexbox/nightly-unstable/
!Issues List: Tracked in spec, and in <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=Flexbox&resolution=---">Bugzilla</a>
Ignored Terms: column-*, auto
Link Defaults: css21 (property) margin/min-width/min-height/max-width/max-height, css-break-3 (property) break-after
</pre>
<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;
}
:not(code) var { font-style: normal; color: #005A9C; }
a > i { font-style: normal; }
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;
F882
padding: .5em;
border-radius: .5em;
}
.axis { color: hsl( 0,80%,40%); }
.side { color: hsl(240,80%,50%); }
.size { color: hsl(120,80%,30%); }
</style>
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
<p>
CSS 2.1 defined four layout modes &mdash; algorithms which determine
the size and position of boxes based on their relationships
with their sibling and ancestor boxes:
<ul class="compact">
<li>block layout, designed for laying out documents
<li>inline layout, designed for laying out text
<li>table layout, designed for laying out 2D data in a tabular format
<li>positioned layout, designed for very explicit positioning without much regard for other elements in the document
</ul>
<p>
This module introduces a new layout mode, <dfn export>flex layout</dfn>,
which is designed for laying out more complex applications and webpages.
<h3 id="overview">
Overview</h3>
<p><em>This section is not normative.</em>
<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/CSS21/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 webapps and complex web pages often need.
The contents of a flex container:
<ul>
<li>
can be laid out in any <a href="#flex-direction-property">flow direction</a>
(leftwards, rightwards, downwards, or even upwards!)
<li>
can have their display order <a href="#flex-flow-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)
<li>
can be laid out linearly along a single (<i title="main axis">main</i>) axis or
<a href="#flex-wrap-property">wrapped</a> into multiple lines along a secondary (<i title="cross axis">cross</i>) axis
<li>
can <a href="#flexibility">&ldquo;flex&rdquo; their sizes</a>
to respond to the available space
<li>
can be <a href="#alignment">aligned</a> with respect to their container or each other
<li>
can be dynamically <a href="#visibility-collapse">collapsed</a> or uncollapsed
along the <i>main axis</i> while preserving the container's <i>cross size</i>
</ul>
<div class='example'>
<p>
Here's an example of a catalog where each item has a title, an 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>
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.
<li>
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,
'order' is used to pull the image up from later in the content to the top,
and 'align-self' is used to center it horizontally.
<li>
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.
</ul>
<pre>
&lt;style>
#deals {
display: flex; /* Flex layout so items <a href="#align-self" title="Flex items stretch by default.">have equal height</a> */
flex-flow: row wrap; /* <a href="http://dev.w3.org/csswg/css3-flexbox/#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 href="#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> */
}
&lt;/style></pre>
<pre>
&lt;section id='deals'>
&lt;section class='sale-item'>
&lt;h1>Computer Starter Kit&lt;/h1>
&lt;p>This is the best computer money can buy, if you don't have much money.
&lt;ul>
&lt;li>Computer
&lt;li>Monitor
&lt;li>Keyboard
&lt;li>Mouse
&lt;/ul>
&lt;img src='images/computer.jpg'
alt='You get: a white computer with matching peripherals.'>
&lt;button>BUY NOW&lt;/button>
&lt;/section>
&lt;section class='sale-item'>
&hellip;
&lt;/section>
&hellip;
&lt;/section></pre>
<figure>
<div id="overview-example">
<div class="col"></div>
<div class="col"></div>
<div class="desc">
<img src="images/computer.jpg" alt='You get: a white computer with matching keyboard and monitor.'>
<h1 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.
<ul>
<li>Computer
<li>Monitor
<li>Keyboard
<li>Mouse
</ul>
</div>
<div class="desc">
<img src="images/printer.png" alt='You get: beautiful ASCII art.'>
<h1 style="font-size: 1.4em;">Printer</h1>
<p>
Only capable of printing
ASCII art.
<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 id="placement">
Module interactions</h3>
<p>
This module extends the definition of the 'display' property [[!CSS21]],
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 ''::first-line'' or ''::first-letter'' pseudo-elements.
<h3 id="values">
Values</h3>
<p>
This specification follows the <a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]].
Value types not defined in this specification are defined in CSS Level 2 Revision 1 [[!CSS21]].
Other CSS modules may expand the definitions of these value types:
for example [[CSS3VAL]], when combined with this module,
expands the definition of the <var>&lt;length&gt;</var> value type as used in this specification.
<p>In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the <a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">''inherit''</a> keyword as their property value. For readability it has not been repeated explicitly.
<h2 id='box-model'>
Flex Layout Box Model and Terminology</h2>
<p>
An element with ''display:flex'' or ''display:inline-flex'' is a <i>flex container</i>.
Children of a flex container are called <i>flex items</i> and are laid out using the flex layout model.
<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 title="flex direction">flex directions</dfn>.
To make it easier to talk about flex layout,
this section defines a set of flex flow&ndash;relative terms.
The 'flex-flow' value determines how these terms map
to physical directions (top/right/bottom/left),
axes (vertical/horizontal), and sizes (width/height).
<figure>
<img src='images/flex-direction-terms.svg' width=665 height=277 alt>
<figcaption>
An illustration of the various directions and sizing terms as applied to a ''row'' flex container.
</figcaption>
</figure>
<dl id="main" export>
<dt class='axis'>main axis
<dt class='axis'>main dimension
<dd>
The <dfn title="main axis|main-axis">main axis</dfn> of a flex container is the primary axis along which <i>flex items</i> are laid out.
It extends in the <dfn>main dimension</dfn>.
<dt class='side'>main-start
<dt class='side'>main-end
<dd>
The <i>flex items</i> are placed within the container
starting on the <dfn>main-start</dfn> side
and going toward the <dfn>main-end</dfn> side.
<dt class='size'>main size
<dt class='size'>main size property
<dd>
A <i>flex item</i>&apos;s width or height,
whichever is in the <i>main dimension</i>,
is the item's <dfn>main size</dfn>.
The <i>flex item</i>&apos;s <dfn>main size property</dfn> is
either the 'width' or 'height' property,
whichever is in the <i>main dimension</i>.
</dl>
<dl id="cross" export>
<dt class='axis'>cross axis
<dt class='axis'>cross dimension
<dd>
The axis perpendicular to the <i>main axis</i> is called the <dfn title="cross axis|cross-axis">cross axis</dfn>.
It extends in the <dfn>cross dimension</dfn>.
<dt class='side'>cross-start
<dt class='side'>cross-end
<dd>
<i>Flex lines</i> are filled with items and placed into the container
starting on the <dfn>cross-start</dfn> side of the flex container
and going toward the <dfn>cross-end</dfn> side.
<dt class='size'>cross size
<dt class='size'>cross size property
<dd>
The width or height of a <i>flex item</i>,
whichever is in the <i>cross dimension</i>,
is the item's <dfn>cross size</dfn>.
The <dfn>cross size property</dfn> is
whichever of 'width' or 'height' that is in the <i>cross dimension</i>.
</dl>
<h2 id='flex-containers'>
Flex Containers: the <a href="#display-flex">''flex''</a> and <a href="#display-inline-flex">''inline-flex''</a> 'display' values</h2>
<pre class="propdef">
Name: display
New values: flex | inline-flex
</pre>
<dl dfn-type=value dfn-for=display>
<dt><dfn>flex</dfn>
<dd>
This value causes an element to generate a block-level <i>flex container</i> box.
<dt><dfn>inline-flex</dfn>
<dd>
This value causes an element to generate an inline-level <i>flex container</i> box.
</dl>
<p>
A <dfn export>flex container</dfn> establishes a new <dfn export>flex formatting context</dfn> for its contents.
This is the same as establishing a block formatting context,
except that flex layout is used instead of block layout:
floats do not intrude into the flex container,
and the flex container's margins do not collapse with the margins of its contents.
<i>Flex containers</i> form a containing block for their contents
<a href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">exactly like block containers do</a>. [[!CSS21]]
The 'overflow' property applies to <i>flex containers</i>.
<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:
<ul>
<li>
all of the 'column-*' properties in the Multicol module have no effect on a flex container.
<li>
'float' and 'clear' have no effect on a <i>flex item</i>.
(However, the 'float' property still affects the computed value of 'display' on children of a flex container,
as this occurs <em title=''>before</em> <i>flex items</i> are determined.)
<li>
'vertical-align' has no effect on a flex item.
<li>
the ''::first-line'' and ''::first-letter'' pseudo-elements do not apply to <i>flex containers</i>.
</ul>
<p>
If an element's specified 'display' is ''inline-flex''
and the element is floated or absolutely positioned,
the computed value of 'display' is <a href="#display-flex">''flex''</a>.
The table in <a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Chapter 9.7</a> is thus amended
to contain an additional row,
with ''inline-flex'' in the "Specified Value" column
and <a href="#display-flex">''flex''</a> in the "Computed Value" column.
<h2 id='flex-items'>
Flex Items</h2>
<p>
The contents of a <i>flex container</i> consists of zero or more <dfn export title="flex item" id="flex-item">flex items</dfn>:
each in-flow child of a <i>flex container</i>
becomes a <i>flex item</i>,
and each contiguous run of text that is directly contained inside a <i>flex container</i>
is wrapped in an anonymous <i>flex item</i>.
However, an anonymous flex item that contains only
<a href="http://www.w3.org/TR/CSS21/text.html#white-space-prop">white space</a>
is not rendered, as if it were ''display:none''.
<p class="note">
Authors reading this spec may want to
<a href="#item-margins">skip past these box-generation details</a>.
<p>
A <i>flex item</i> establishes a new formatting context for its contents.
The type of this formatting context is determined by its 'display' value, as usual.
The computed 'display' of a <i>flex item</i>
is determined by applying the table in
<a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Chapter 9.7</a>
(except that internal table elements are instead handled by anonymous box fixup, see below).
However, flex items are flex-level boxes, not block-level boxes:
they participate in their container's flex formatting context,
not in a block formatting context.
<p class='note'>
The 'display' computation on flex items as defined here
is expected to be superseded by a future specification
that defines a new 'display' value specific to flex items.
<div class="example">
<p>Examples of flex items:
<pre>
&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 split around blocks -->
&lt;div id=not-an-item>item 4&lt;/div>
item 4
&lt;/span>
&lt;/div></pre>
</div>
<p>
Some values of 'display' trigger the generation of anonymous boxes.
For example, a misparented ''table-cell'' child is fixed up
by <a href="http://www.w3.org/TR/CSS21/tables.html#anonymous-boxes">generating anonymous ''table'' and ''table-row'' elements</a> around it. [[!CSS21]]
This fixup must occur <em>before</em> a flex container's children are promoted to <i>flex items</i>.
For example, given two contiguous child elements with ''display:table-cell'',
an anonymous table wrapper box around them becomes the <i>flex item</i>.
<p class='note'>
Future display types may generate anonymous containers (e.g. ruby) or otherwise mangle the box tree (e.g. run-ins).
It is intended that flex item determination run after these operations.
<p id="table-items">
On a flex item with ''display: table'', the table wrapper box becomes the <i>flex item</i>,
and the 'order' and 'align-self' properties apply to it.
The contents of any caption boxes contribute to the calculation of
the table wrapper box's min-content and max-content sizes.
However, like 'width' and 'height', the 'flex' longhands apply to the table box as follows:
the <i>flex item</i>&apos;s final size is calculated
by performing layout as if the distance between
the table wrapper box's edges and the table box's content edges
were all part of the table box's border+padding area,
and the table box were the <i>flex item</i>.
<h3 id='abspos-items'>
Absolutely-Positioned Flex Children</h3>
An absolutely-positioned child element of a <i>flex container</i> does not participate in flex layout
beyond the <a href="#algo-flex-order">reordering step</a>.
Its static position is calculated by first doing full flex layout without the absolutely-positioned elements,
then positioning each absolutely-positioned child as if it were the sole <a>flex item</a>
in the <a>flex container</a>,
assuming it was a fixed size box of its used size.
<div class='example'>
For example, by default, the static position of an absolutely positioned element aligns it to the main-start/cross-start corner,
corresponding to the default values of 'justify-self' and 'align-self'.
Setting ''justify-self:center'', however,
would center it in the main axis.
</div>
<h3 id='item-margins'>
Flex Item Margins and Paddings</h3>
<p>
The margins of adjacent <i>flex items</i> do not collapse.
Auto margins absorb extra space in the corresponding dimension and can be used for alignment
and to push adjacent flex items apart;
see <a href="#auto-margins">Aligning with <span class=css>auto</span> margins</a>.
<p>
Percentage margins and paddings on <i>flex items</i> are always resolved against their respective dimensions;
unlike blocks, they do not always resolve against the inline dimension of their containing block.
<h3 id='painting'>
Flex Item Z-Ordering</h3>
<p>
<i>Flex items</i> paint exactly the same as inline blocks [[!CSS21]],
except that 'order'-modified document order is used in place of raw document order,
and <a href="http://www.w3.org/TR/CSS21/visuren.html#propdef-z-index">'z-index'</a>
values other than <a value for=z-index>auto</a> create a stacking context
even if 'position' is ''static''.
<p class="note">
Note: Descendants that are positioned outside a flex item still participate
in any stacking context established by the flex item.
<h3 id='visibility-collapse'>
Collapsed Items</h3>
<p>
Specifying ''visibility:collapse'' on a flex item
causes it to become a <dfn title="collapsed flex item|collapsed">collapsed flex item</dfn>,
producing an effect similar to ''visibility:collapse'' on a table-row or table-column:
the collapsed element 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
is guaranteed to have no effect on the flex container's <i>cross size</i>
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>
Though collapsed flex items aren't rendered,
they do appear in the <a href="http://www.w3.org/TR/CSS21/intro.html#formatting-structure">formatting structure</a>.
Therefore, unlike on ''display:none'' items [[!CSS21]],
effects that depend on an element appearing in the formatting structure
(like incrementing counters or running animations and transitions)
still operate on collapsed items.
<div class="example">
<p>In the following example,
a sidebar is sized to fit its content.
''visibility: collapse'' is used to dynamically hide parts of a navigation sidebar
without affecting its width, even though the widest item (&ldquo;Architecture&rdquo;)
is in a collapsed section.
<figure>
<figcaption>Sample rendering for example code below</figcaption>
<div id="visibility-collapse-example">
<!-- No, don't look at this source code, look at the other source code. -->
<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>
<li><a href="#">Events</a>
</ul>
</ul>
</nav>
<article>
Interesting Stuff to Read
</article>
</div>
</figure>
<pre>
&lt;style>
@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) */
header + 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;
}
&lt;/style>
&hellip;
&lt;/header>
&lt;div>
&lt;article id="main">
Interesting Stuff to Read
&lt;/article>
&lt;nav>
&lt;ul>
&lt;li id="nav-about">&lt;a href="#nav-about">About&lt;/a>
&hellip;
&lt;li id="nav-projects">&lt;a href="#nav-projects">Projects&lt;/a>
&lt;ul>
&lt;li>&lt;a href="&hellip;">Art&lt;/a>
&lt;li>&lt;a href="&hellip;">Architecture&lt;/a>
&lt;li>&lt;a href="&hellip;">Music&lt;/a>
&lt;/ul>
&lt;li id="nav-interact">&lt;a href="#nav-interact">Interact&lt;/a>
&hellip;
&lt;/ul>
&lt;/nav>
&lt;/div>
&lt;footer>
&hellip;
</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 ''visibility:collapse''
interacts with flex layout.
<p class='note'>
Note that using ''visibility:collapse'' 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 ''display:none'' 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 'visibility' is changed,
however, 'visibility: collapse' is still recommended for dynamic cases.)
<h2 id="flow-order">
Ordering and Orientation</h2>
<p>
The contents of a flex container can be laid out in any direction and in any order.
This allows an author to trivially achieve effects that would previously have required complex or fragile methods,
such as hacks using the 'float' and 'clear' properties.
This functionality is exposed through the 'flex-direction', 'flex-wrap', and 'order' properties.
<p class="note">
The reordering capabilities of flex layout intentionally affect
<em>only the visual rendering</em>,
leaving speech order and navigation based on the source order.
This allows authors to manipulate the visual presentation
while leaving the source order intact for non-CSS UAs and for
linear models such as speech and sequential navigation.
See <a href="#order-accessibility">Reordering and Accessibility</a>
and the <a href="#overview">Flex Layout Overview</a> for examples
that use this dichotomy to improve accessibility.
<p>
Authors <em>must not</em> use these techniques as a substitute for correct source ordering,
as that can ruin the accessibility of the document.
<h3 id='flex-direction-property'>
Flex Flow Direction: the 'flex-direction' property</h3>
<pre class='propdef'>
Name: flex-direction
Value: row | row-reverse | column | column-reverse
Initial: row
Applies to: <a>flex containers</a>
Inherited: no
Computed value: specified value
Media: visual
</pre>
<p>
The 'flex-direction' property specifies how <i>flex items</i> are placed in the flex container,
by setting the direction of the flex container's <i>main axis</i>.
This determines the direction that flex items are laid out in.
<dl dfn-type=value dfn-for=flex-direction>
<dt><dfn>row</dfn>
<dd>
The flex container's <i>main axis</i> has the same orientation as the
<a>inline axis</a>
of the current <i>writing mode</i>.
The <i>main-start</i> and <i>main-end</i> directions are equivalent to the
<a>inline-start</a> and
<a>inline-end</a> directions, respectively,
of the current <i>writing mode</i>.
<dt><dfn>row-reverse</dfn>
<dd>
Same as ''row'',
except the <i>main-start</i> and <i>main-end</i> directions are swapped.
<dt><dfn>column</dfn>
<dd>
The flex container's <i>main axis</i> has the same orientation as the
<a>block axis</a>
of the current <i>writing mode</i>.
The <i>main-start</i> and <i>main-end</i> directions are equivalent to the
<a>block-start</a> and
<a>block-end</a> directions, respectively,
of the current <i>writing mode</i>.
<dt><dfn>column-reverse</dfn>
<dd>
Same as ''column'',
except the <i>main-start</i> and <i>main-end</i> directions are swapped.
</dl>
<p class="note">
The reverse values do not reverse box ordering;
like 'writing-mode' and 'direction' [[CSS3-WRITING-MODES]],
they only change the direction of flow.
Painting order, speech order, and sequential navigation orders
are not affected.
<h3 id='flex-wrap-property'>
Flex Line Wrapping: the 'flex-wrap' property</h3>
<pre class='propdef'>
Name: flex-wrap
Value: nowrap | wrap | wrap-reverse
Initial: nowrap
Applies to: <a>flex containers</a>
Inherited: no
Computed value: specified value
Media: visual
</pre>
<p>
The 'flex-wrap' property controls whether the flex container is <i>single-line</i> or <i>multi-line</i>,
and the direction of the <i>cross-axis</i>,
which determines the direction new lines are stacked in.
<dl dfn-type=value dfn-for=flex-wrap>
<dt><dfn>nowrap</dfn>
<dd>
The flex container is <i>single-line</i>.
The <i>cross-start</i> direction is equivalent to either
the <a>inline-start</a>
or <a>block-start</a>
direction of the current <i>writing mode</i>,
whichever is in the <i>cross axis</i>,
and the <i>cross-end</i> direction is the opposite direction of <i>cross-start</i>.
<dt><dfn>wrap</dfn>
<dd>
The flex container is <i>multi-line</i>.
The <i>cross-start</i> direction is equivalent to either
the <a>inline-start</a>
or <a>block-start</a>
direction of the current <i>writing mode</i>,
whichever is in the <i>cross axis</i>,
and the <i>cross-end</i> direction is the opposite direction of <i>cross-start</i>.
<dt><dfn>wrap-reverse</dfn>
<dd>
Same as ''wrap'',
except the <i>cross-start</i> and <i>cross-end</i> directions are swapped.
</dl>
<h3 id='flex-flow-property'>
Flex Direction and Wrap: the 'flex-flow' shorthand</h3>
<pre class='propdef'>
Name: flex-flow
Value: <'flex-direction'> || <'flex-wrap'>
Initial: see individual properties
Applies to: <a>flex containers</a>
Inherited: see individual properties
Computed value: see individual properties
Media: visual
</pre>
<p>The 'flex-flow' property is a shorthand for setting the 'flex-direction' and 'flex-wrap' properties,
which together define the flex container's main and cross axes.
<div class="example">
<p>Some examples of valid flows in an English (left-to-right, horizontal writing mode) document:
<table style="margin: 0 auto; vertical-align: middle; border-spacing: 2em 1em;">
<tr>
<td><pre>
div { flex-flow: row; }
/* Initial value. Main-axis is
inline, no wrap. */</pre>
<td><img src='images/flex-flow1.svg' width=205 height=46 alt>
<tr>
<td><pre>
div { flex-flow: column wrap; }
/* Main-axis is block-direction (top to bottom)
and lines wrap in the inline direction (rightwards). */</pre>
<td><img src='images/flex-flow2.svg' width=89 height=160 alt>
<tr>
<td><pre>
div { flex-flow: row-reverse wrap-reverse; }
/* Main-axis is the opposite of inline direction
(right to left). New lines wrap upwards. */</pre>
<td><img src='images/flex-flow3.svg' width=160 height=89 alt>
</table>
</div>
<div class='note'>
<p>
Note that the 'flex-flow' directions are <i>writing mode</i> sensitive.
In vertical Japanese, for example,
a ''row'' flex container lays out its contents from top to bottom,
as seen in this example:
<table style="margin: 1em auto; text-align: center;">
<thead>
<tr>
<th>English
<th>Japanese
<tbody>
<tr>
<td><pre>flex-flow: row wrap;<br>writing-mode: horizontal-tb;</pre>
<td><pre>flex-flow: row wrap;<br>writing-mode: vertical-rl;</pre>
<tr>
<td><img src='images/flex-flow-english.svg' alt>
<td><img src='images/flex-flow-japanese.svg' alt>
</table>
</div>
<h3 id='order-property'>
Display Order: the 'order' property</h3>
<p>
<i>Flex items</i> are, by default, displayed and laid out in the same order as they appear in the source document.
The 'order' property can be used to change this ordering.
<pre class='propdef'>
Name: order
Value: <<integer>>
Initial: 0
Applies to: <a>flex items</a> and absolutely-positioned children of <a>flex containers</a>
Inherited: no
Computed value: specified value
Media: visual
Animatable: yes
</pre>
<p>