8000 csswg-drafts/css-multicol/Overview.bs at 6a18bf9594c81321460c700ff39035f2a3d9a1a4 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1752 lines (1436 loc) · 49.2 KB

File metadata and controls

1752 lines (1436 loc) · 49.2 KB
<pre class="metadata">
Title: CSS Multi-column Layout Module Level 1
Group: CSSWG
Shortname: css-multicol
Level: 1
Status: ED
Work Status: Testing
ED: https://drafts.csswg.org/css-multicol/
TR: https://www.w3.org/TR/css3-multicol/
Previous Version: https://www.w3.org/TR/2011/CR-css3-multicol-20110412/
Previous Version: https://www.w3.org/TR/2009/CR-css3-multicol-20091217/
Previous Version: https://www.w3.org/TR/2009/WD-css3-multicol-20090630/
Previous Version: https://www.w3.org/TR/2007/WD-css3-multicol-20070606/
Previous Version: https://www.w3.org/TR/2005/WD-css3-multicol-20051215/
Previous Version: https://www.w3.org/TR/2001/WD-css3-multicol-20010118/
Previous Version: http://www.w3.org/1999/06/WD-css3-multicol-19990623
Editor: Håkon Wium Lie, Opera Software, howcome@opera.com
Abstract: This specification describes multi-column layouts in CSS, a style sheet language for the web. Using functionality described in the specification, content can be flowed into multiple columns with a gap and a rule between them.
Link Defaults: css-color (property) color, css21 (property) max-height
</pre>
<style type="text/css">
.cols { width: 500px; height: 200px; background: #fff; position: relative; border: solid 5px blue; margin: 0.5em 2em 1em 0; font: bold 14px/19px Arial, sans-serif }
.cols p { padding: 3px; margin: 0 }
.col { position: absolute; left: 0px; top: 0; z-index: 6; width: 170px }
.gap { position: absolute; background: green; width: 5px; bottom: 0px; top: 0px; border: 10px solid yellow; border-top-width: 0; border-bottom-width: 0; }
.rep { position: absolute; top: 45px; background: black; height: 110px; width: 100px; color: white; z-index: 4 }
table.breaks { border-collapse: collapse; margin: 1em 0 }
table.breaks td, table.breaks th { border: thin solid black; padding: 0.1em 0.2em }
div.example:before { width: 9em }
</style>
<h2 id="introduction">
Introduction</h2>
(This section is not normative.)
This module describes multi-column layout in CSS. By using
functionality described in this document, style sheets can declare
that the content of an element is to be laid out in multiple
columns.
On the Web, tables have also been used to describe multi-column
layouts. The main benefit of using CSS-based columns is flexibility;
content can flow from one column to another, and the number of columns
can vary depending on the size of the viewport. Removing presentation
table markup from documents allows them to more easily be presented on
various output devices including speech synthesizers and small mobile
devices.
Multi-column layouts are easy to describe in CSS. Here is a simple example:
<div class=example>
<pre>body { column-width: 12em }</pre>
In this example, the <code class=html>body</code> element is
set to have columns at least ''12em'' wide. The exact number of
columns will depend on the available space.
</div>
The number of columns can also be set explicitly in the style sheet:
<div class=example>
<pre>body { column-count: 2 }</pre>
In this case, the number of columns is fixed and the column widths
will vary depending on the available width.
</div>
The shorthand 'columns' property can be used to set either,
or both, properties in one declaration.
<div class=example>
In these examples, the number of columns, the width of columns, and
both the number and width are set, respectively:
<pre>
body { columns: 2 }
body { columns: 12em }
body { columns: 2 12em }
</pre>
However, as described below, setting both the width and number of
columns rarely makes sense.
</div>
Another group of properties introduced in this module describe
gaps and rules between columns.
<div class=example>
<pre>
body {
column-gap: 1em;
column-rule: thin solid black;
}
</pre>
The first declaration in the example above sets the gap between two
adjacent columns to be 1em. Column gaps are similar to padding areas.
In the middle of the gap there will be a rule which is described by
the 'column-rule' property.
</div>
The values of the 'column-rule' property are similar to those of
the CSS border properties. Like 'border', 'column-rule' is a
shorthand property.
<div class=example>
In this example, the shorthand 'column-rule' declaration from the
above example has been expanded:
<pre>
body {
column-gap: 1em;
column-rule-width: thin;
column-rule-style: solid;
column-rule-color: black;
}
</pre>
</div>
The 'column-fill' and 'column-span' properties give style sheets a
wider range of visual expressions in multi-column layouts.
<div class=example>
In this example, columns are set to be balanced, i.e., to have
approximately the same length. Also, <code>h2</code> elements are set
to span across all columns.
<pre>
div { column-fill: balance }
h2 { column-span: all }
</pre>
</div>
This specification introduces ten new properties, all of which
are used in the examples above.
To indicate where column breaks should (or should not) appear, new
keyword values are introduced.
<div class=example>
In this example, <code>h1</code> elements will always have a column
break before them, but the formatter will try to avoid column breaks
inside and after the element.
<pre>
h1 {
break-before: column;
break-inside: avoid-column;
break-after: avoid-column;
}
</pre>
<!--
The properties and values used in this example are formally defined in [!CSS3PAGE]].
-->
</div>
If all column properties have their initial value, the layout of
an element will be identical to a multi-column layout with only one
column.
<h2 id="the-multi-column-model">
The multi-column model</h2>
A <dfn lt="multi-column element|multicol element" export>multi-column element</dfn>
(or <em>multicol element</em> for short)
is an element whose 'column-width' or 'column-count'
property is not ''column-width/auto'' and therefore acts as a container for
multi-column layout.
In the traditional CSS box model, the content of an element is
flowed into the content box of the corresponding element. Multi-column
layout introduces a new type of container between the content box and
the content, namely the <dfn>column box</dfn> (or <em>column</em> for
short). The content of a multicol element is flowed into its column
boxes.
Column boxes in a multi-column element are arranged
into <em>rows</em>. Like table cells, the column boxes in a row are
ordered in the inline direction of the multicol element. The
<em>column width</em> is the length of the column box in the inline
direction. The <em>column height</em> is the length of the column box
in the block direction. All column boxes in a row have the same column width, and all
column boxes in a row have the same column height. Within each row in the multi-column element,
adjacent column boxes are separated by a <em>column gap</em>, which
may contain a <em>column rule</em>. All column gaps in the same row
are equal. All column rules in the same row are also equal, if they
appear; column rules only appear between columns that both have
content.
In the simplest case a multicol element will contain only one row
of columns, and the height of each column will be equivalent to the
used height of the multi-column element's content box.
<div class="example">
Column gaps (yellow) and column rules (green) are shown in this
sample rendition of a multi-column element with padding (blue). The
blue and yellow is present for illustrational purposes only. In actual
implementations these areas will be determined by the background.
<div class=cols>
<div class="col" style="">
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs
</div>
<div class="col" style="left: 175px">
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
</div>
<div class="col" style="left: 350px">
M nop qrst uv wx yz.<br>
<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
Pqr stu vw xyz.
</div>
<div class=gap style="left: 150px"></div>
<div class=gap style="left: 325px"></div>
</div>
</div>
If the multi-column element is paginated, the height of each row is
constrained by the page and the content continues in a new row of
column boxes on the next page; a column box never splits across pages.
The same effect occurs when a <em>spanning element</em> divides the
multi-column element: the columns before the spanning element are
balanced and shortened to fit their content. Content after the
spanning element then flows into a new row of column boxes.
<div class="example">
<div class=cols>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
<br>
<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
<div class="col" style="left: 175px">
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
<br>
<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
</div>
<div class="col" style="left: 350px">
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
<br>
<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz.
</div>
<div class=rep style="width: 490px; height: 20px; background: silver; font-size: 1.5em; padding: 5px">A spanning element</div>
<div class=gap style="left: 150px"></div>
<div class=gap style="left: 325px"></div>
</div>
</div>
<!--
To illustrate the effects of the various properties described in
this specification, variations on a sample document will be used. Here
is the source code of the sample document:
<pre class="html">
&lt;html>
&lt;style type="text/css">
div {
column-width: 15em;
column-gap: 2em; /* shown in yellow */
column-rule: 4px solid green;
padding: 5px; /* shown in blue */
}
p { margin: 0; padding: 0 }
img { display: none }
&lt;/style>
&lt;body>
&lt;div>
&lt;p&gt;Ab cde fgh i jkl. Mno
pqr stu vw xyz. A bc
&lt;img src=...>
def g hij
...
&lt;/div>
&lt;/body>
&lt;/html>
</pre>
The nonsensical text in the example is the English alphabet which
shows how text flows from one column to another. To simplify the
visualization, the textual content of the different examples vary
slightly.
-->
Column boxes are block container boxes. That
is, column boxes behave like block-level, table cell, and inline-block
boxes as per CSS 2.1, section 10.1, item 2 [[!CSS21]]. However, column
boxes do not establish block container boxes for elements with ''position:
fixed'' or ''position: absolute''.
<div class=example>
In this example, the width of the image is set with these rules:
<pre class=css>
img { display: block; width: 100% }
</pre>
Given that the width is calculated relative to the column box, the
image will be as wide as the column box:
<div class=cols>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
<br>
<br>
<br>
<br>
<br>
<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
<div class="col" style="left: 175px">
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
</div>
<div class="col" style="left: 350px">
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz.
</div>
<div class=rep style="width: 150px"></div>
<div class=gap style="left: 150px"></div>
<div class=gap style="left: 325px"></div>
</div>
</div>
Floats that appear inside multi-column layouts are positioned with
regard to the column box where the float appears.
<div class="example">
In this example, this CSS fragment describes the presentation of the image:
<pre class="css">
img { display: block; float: right }
</pre>
<div class=cols>
<div class="col" style="">
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g<br>
hij klm<br>
nopq<br>
rs tuv<br>
wxy x<br>
yz. Ab <br>
cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc
</div>
<div class="col" style="left: 175px">
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
</div>
<div class="col" style="left: 350px">
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
</div>
<div class=rep style="left: 50px"></div>
<div class=gap style="left: 150px"></div>
<div class=gap style="left: 325px"></div>
</div>
The black box represents the image.
</div>
A multi-column element establishes a new block formatting context,
as per CSS 2.1 section 9.4.1.
<div class="example">
A top margin set on the first child element of a multicol element will not collapse with the margins of the multicol element.
</div>
Nested multi-column elements are allowed, but there may be
implementation-specific limits.
Note: It is not possible to set properties/values on column boxes. For
example, the background of a certain column box cannot be set and a
column box has no concept of padding, margin or borders. Future specifications may add additional
functionality. For example, columns of different widths and different
backgrounds may be supported.
Note: Multicol elements with column heights larger than the viewport may pose accessibility issues.
<h2 id="the-number-and-width-of-columns">
The number and width of columns</h2>
Finding the number and width of columns is fundamental when laying
out multi-column content. These properties are used to set the number
and width of columns:
<!--When the block direction
is unconstrained and no column breaks are added through style sheets,
these two properties determine the outcome:-->
<ul>
<li>'column-count'
<li>'column-width'
</ul>
A third property, 'columns', is a shorthand property which sets both
'column-width' and 'column-count'.
Other factors, such as explicit column breaks, content, and height
constraints, may influence the actual number and width of columns.
<h3 id='cw'>
'column-width'</h3>
<pre class=propdef>
Name: column-width
Value: auto | <<length>>
Initial: auto
Applies to: non-replaced block-level elements (except table elements), table cells, and inline-block elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: the absolute length, zero or larger
Animatable: as <<length>>
</pre>
This property describes the width of columns in multicol elements.
<dl dfn-type=value dfn-for=column-width>
<dt><dfn>auto</dfn>
<dd>
means that the column width will be determined by other properties
(e.g., 'column-count', if it has a non-auto value).
<dt><dfn><<length>></dfn>
<dd>
describes the optimal column width. The actual column width may be
wider (to fill the available space), or narrower (only if the
available space is smaller than the specified column width). Specified values
must be greater than 0.
</dl>
<div class=example>
For example, consider this style sheet:
<pre>
div {
width: 100px;
column-width: 45px;
column-gap: 0;
column-rule: none;
}
</pre>
There is room for two 45px wide columns inside the 100px wide element. In
order to fill the available space the actual column width will be
increased to 50px.
</div>
<div class=example>
Also, consider this style sheet:
<pre>
div {
width: 40px;
column-width: 45px;
column-gap: 0;
column-rule: none;
}
</pre>
The available space is smaller than the specified column width and
the actual column width will therefore be decreased.
</div>
To ensure that 'column-width' can be used with vertical text,
column width means the length of the line boxes inside the columns.
Note: The reason for making 'column-width' somewhat flexible
is to achieve scalable designs that can fit many screen sizes. To set
an exact column width, the column gap and the width of the multicol
element (assuming horizontal text) must also be specified.
<h3 id='cc'>
'column-count'</h3>
<pre class=propdef>
Name: column-count
Value: auto | <<integer>>
Initial: auto
Applies to: non-replaced block-level elements (except table elements), table cells, and inline-block elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value
Animatable: as <<integer>>
</pre>
This property describes the number of columns of a multicol element.
<dl dfn-type=value dfn-for=column-count>
<dt><dfn>auto</dfn>
<dd>
means that the number of columns will be determined by other properties
(e.g., 'column-width', if it has a non-auto value).
<dt><dfn><<integer>></dfn>
<dd>
describes the optimal number of columns into which the content of
the element will be flowed. Values must be greater than 0. If both
'column-width' and 'column-count' have non-auto values, the integer
value describes the maximum number of columns.
</dl>
<div class=example>
Example:
<pre>body { column-count: 3 }</pre>
</div>
<h3 id="columns">
'columns'</h3>
<pre class=propdef>
Name: columns
Value: <<'column-width'>> || <<'column-count'>>
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Percentages: see individual properties
Media: see individual properties
Computed value: see individual properties
Animatable: see individual properties
</pre>
This is a shorthand property for setting 'column-width' and
'column-count'. Omitted values are set to their initial values.
<div class="example">
Here are some valid declarations using the 'columns' property:
<pre>
columns: 12em; /* column-width: 12em; column-count: auto */
columns: auto 12em; /* column-width: 12em; column-count: auto */
columns: 2; /* column-width: auto; column-count: 2 */
columns: 2 auto; /* column-width: auto; column-count: 2 */
columns: auto; /* column-width: auto; column-count: auto */
columns: auto auto; /* column-width: auto; column-count: auto */
</pre>
</div>
<h3 id="pseudo-algorithm">
Pseudo-algorithm</h3>
The pseudo-algorithm below determines the used values for
'column-count' (N) and 'column-width' (W) when . There is one other variable
in the pseudo-algorithm: U is the used width of the multi-column
element.
Note: The used width U of the multi-column element can depend on the element's contents,
in which case it also depends on the computed values of the 'column-count' and 'column-width' properties.
This specification does not define how U is calculated.
Another module
(probably the Basic Box Model [[CSS3BOX]] or the Intrinsic & Extrinsic Sizing Module [[CSS3-SIZING]])
is expected to define this.
<!--
Two assumptions are being made by the pseudo-algorithm:
<ul>
<li>that the block direction is unconstrained
<li>that no column breaks are added through style sheets
</ul>
-->
The <code>floor(X)</code> function returns the largest integer Y &le; X.
<pre>
(01) if ((column-width = auto) and (column-count = auto)) then
(02) exit; /* not a multicol element */
(03) if column-width = auto then
(04) N := column-count
(05) else if column-count = auto then
(06) N := max(1,
(07) floor((U + column-gap)/(column-width + column-gap)))
(08) else
(09) N := min(column-count, max(1,
(10) floor((U + column-gap)/(column-width + column-gap))))
</pre>
And:
<pre>
(11) W := max(0, ((U + column-gap)/N - column-gap))
</pre>
In paged media, user agents may perform this calculation on a
per-page basis.
The used value for 'column-count' is calculated without
regard for explicit column breaks or constrained column heights,
while the actual value takes these into consideration.
<div class=example>
In this example, the actual column-count is higher than the used column-count due to explicit column breaks:
<pre>
div { width: 40em; columns: 20em; column-gap: 0 }
p { break-after: column }
&lt;div>
&lt;p>one
&lt;p>two
&lt;p>three
&lt;/div>
</pre>
The computed column-count is auto, the used column-count is 2 and the actual column-count is 3.
</div>
<div class=example>
The actual column-count may be lower than the used column-count. Consider this example:
<pre>
div {
width: 80em;
height: 10em;
columns: 20em;
column-gap: 0;
column-fill: auto;
}
&lt;div>foo&lt;/div>
</pre>
The computed column-count is auto, the used column-count is 4, and the actual column-count is 1.
</div>
<h3 id="stacking-context">
Stacking context</h3>
All column boxes in a multi-column element are in the same stacking
context and the drawing order of their contents is as specified in
CSS 2.1. Column boxes do not establish new stacking contexts.
<h2 id="column-gaps-and-rules">
Column gaps and rules</h2>
Column gaps and rules are placed between columns in the same
multicol element. The length of the column gaps and column rules
is equal to the column height. Column gaps take up space. That
is, column gaps will push apart content in adjacent columns (within
the same multicol element).
A column rule is drawn in the middle of the column gap with the
endpoints at opposing content edges of the multicol element. Column
rules do not take up space. That is, the presence or thickness of a
column rule will not alter the placement of anything else. If a column
rule is wider than its gap, the adjacent column boxes will overlap the
rule, and the rule may possibly extend outside the box of the multicol
element. Column rules are painted in the inline content layer, but
below all inline content inside the multicol element. Column rules are
only drawn between two columns that both have content.
<h3 id='column-gap'>
'column-gap'</h3>
<pre class=propdef>
Name: column-gap
Value: <<length>> | normal
Initial: normal
Applies to: CD6 <a>multicol elements</a>
Inherited: no
Percentages: N/A
Media: visual
Computed value: absolute length or ''normal''
Animatable: as <<length>>
</pre>
<dl dfn-type=value dfn-for=column-gap>
<dt><dfn><<length>></dfn>
<dd>
Specifies the gap between columns.
If there is a column rule between columns,
it will appear in the middle of the gap.
The <<length>> cannot be negative.
<dt><dfn>normal</dfn>
<dd>
Identical to <a value for="column-gap">&lt;length></a>,
but with a UA-specified length.
A value of ''1em'' is suggested.
</dl>
<h3 id='crc'>
'column-rule-color'</h3>
<pre class=propdef>
Name: column-rule-color
Value: <<color>>
Initial: currentcolor
Applies to: multicol elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: same as the computed value of 'color' is computed
Animatable: as <<color>>
</pre>
<dl>
<dt><dfn value for=column-rule-color><<color>></dfn>
<dd>
Specifies the color of the column rule.
</dl>
<h3 id='crs'>
'column-rule-style'</h3>
<pre class=propdef>
Name: column-rule-style
Value: <<'border-style'>>
Initial: none
Applies to: multicol elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value
Animatable: no
</pre>
The 'column-rule-style' property sets the style of the rule between columns of an element.
The <<'border-style'>> values are interpreted as in the <a href="https://www.w3.org/TR/CSS2/tables.html#collapsing-borders">collapsing border model</a>.
The ''border-style/none'' value forces the computed value of 'column-rule-width' to be ''0''.
<h3 id='crw'>
'column-rule-width'</h3>
<pre class=propdef>
Name: column-rule-width
Value: <<'border-width'>>
Initial: medium
Applies to: multicol elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: absolute length; ''0'' if the column rule style is ''none'' or ''hidden''
Animatable: as <<length>>
</pre>
This property sets the width of the rule between columns.
Negative values are not allowed.
<h3 id="column-rule">
'column-rule'</h3>
<pre class=propdef>
Name: column-rule
Value: <<'column-rule-width'>> || <<'column-rule-style'>> || <<'column-rule-color'>>
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Percentages: see individual properties
Media: see individual properties
Computed value: see individual properties
Animatable: see individual properties
</pre>
This property is a shorthand for setting
'column-rule-width', 'column-rule-style', and 'column-rule-color' at
the same place in the style sheet. Omitted values are set to their
initial values.
<div class=example>
In this example, the column rule and the column gap have the same
width. Therefore, they will occupy exactly the same space.
<pre>
body {
column-gap: 1em;
column-rule-width: 1em;
column-rule-style: solid;
column-rule-color: black;
}
</pre>
</div>
<div class=example>
If a tall image is moved to a column on the next page to find room
for it, its natural column may be left empty. If so, the column is
still considered to have content for the purpose of deciding if the
column rule should be drawn.
</div>
<h2 id="column-breaks">
Column breaks</h2>
When content is laid out in multiple columns, the user agent must
determine where column breaks are placed. The problem of breaking
content into columns is similar to breaking content into pages, which
is described in CSS 2.1, section 13.3.3 [[!CSS21]].
Three new properties are introduced to allow column breaks to be
described in the same properties as page breaks: 'break-before',
'break-after', and 'break-inside'.
<h3 id="break-before-break-after-break-inside">
'break-before', 'break-after', 'break-inside'</h3>
'break-before', 'break-after', and 'break-inside'
are defined in [[!CSS3-BREAK]].
<h2 id="spanning-columns">
Spanning columns</h2>
The 'column-span' property makes it possible for an element to span across several columns.
<h3 id="column-span">
'column-span'</h3>
<pre class="propdef">
Name: column-span
Value: none | all
Initial: none
Applies to: in-flow block-level elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value
</pre>
This property describes how many columns an element spans across. Values are:
<dl dfn-type=value dfn-for=column-span>
<dt><dfn>none</dfn>
<dd>
The element does not span multiple columns.
<dt><dfn>all</dfn>
<dd>
The element spans across all columns of the nearest multicol
ancestor in the same block formatting context. The element spans
across all columns. Content in the normal flow that appears before the
element is automatically balanced across all columns before the
element appears. The element establishes a new block formatting
context.
</dl>
An element that spans more than one column is called a
<dfn export>spanning element</dfn> and the box it creates is called a <dfn export>spanner</dfn>.
<!--
This property has no effect on elements that do not fit entirely
within the multicol element. Also, if a setting on this property pushes the
element outside a multicol element, this property will have no effect.
-->
<div class="example">
In this example, an <code>h2</code> element has been added to the
sample document after the sixth sentence (i.e., after the word "jkl."). This styling applies:
<pre class="css">
h2 { column-span: all; background: silver }
</pre>
By setting 'column-span' to ''column-span/all'', all content that appear before
the <code>h2</code> element is shown before the <code>h2</code>
element.
<div class=cols>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
<br><br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
hi jklmno. Pqrstu vw<br>
<div class="col" style="left: 175px">
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
<br><br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>
Ab cde fgh i jkl. Mno<br>
pqr stu vw xyz. A bc<br>
def g hij klm nopqrs<br>
tuv wxy z. Abc de fg<br>
</div>
<div class="col" style="left: 350px">
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
<br><br>
hi jklmno. Pqrstu vw<br>
x yz. Abc def ghi jkl.<br>
M nop qrst uv wx yz.<br>