8000 csswg-drafts/css3-box/Overview.src.html at 0fea5ace83145f7649da9ad194a47b8788e3ca95 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
5337 lines (4240 loc) · 195 KB

File metadata and controls

5337 lines (4240 loc) · 195 KB
<!doctype html public '-//W3C//DTD HTML 4.01//EN'>
<head profile="http://www.w3.org/2006/03/hcard
http://microformats.org/wiki/rel-license">
<meta content="text/html; charset=utf-8" http-equiv=content-type>
<title>CSS basic box model</title>
<style type="text/css">
ol.stack p {margin-top: 0}
img.small {max-width: 100%}
</style>
<link rel=contents href="#contents">
<link rel=index href="#index">
<link href="../default.css" rel="stylesheet"
title="Default" type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-MO.css" rel="stylesheet"
title="Default" type="text/css">
<div class="head">
<!--logo-->
<h1>CSS basic box model</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE: 26 Sep 2006]</h2>
<dl>
<dt>This version:
<dd><a href="[VERSION]">
http://www.w3.org/TR/[YEAR]/ED-css3-box-[CDATE]</a>
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/css3-box">
http://www.w3.org/TR/css3-box</a>
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2002/WD-css3-box-20021024">
http://www.w3.org/TR/2002/WD-css3-box-20021024</a>
<dt>Editors:
<dd class=vcard><span class=fn>Bert Bos</span> (<span
class=org>W3C</span>) <span class=email>bert@w3.org</span>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc">Abstract</h2>
<p><abbr title="Cascading Style Sheets">CSS</abbr> describes the
rendering of documents on various media. When textual documents (e.g.,
HTML) are laid out on visual media (e.g., screen or print), CSS models
their layout as a collection of rectangular boxes containing words, lines,
paragraphs, tables, etc., each with properties such as size, color and
font.
<p>This module describes the basic types of boxes: block, list item,
inline, etc.; and some of their properties, including margins, padding
and width/height. It defines a layout called a “flow,” in which a
series of boxes is laid out one after the other, and it defines
“floating” boxes. Other kinds of layout, such as tables, absolute
positioning, ruby annotations, grid layouts, columns and page boxes,
are described by other modules. Also, the layout of text inside a line
(including the handling of left-to-right and right-to-left scripts) is
defined elsewhere.
<p>In CSS level 3, boxes may contain either horizontal or vertical text.
Different orientations can be mixed.
<h2 class="no-toc no-num">Status of this document</h2>
<!--status-->
<p>The CSS Working Group plans to ask for W3C Recommendation status
for this specification only when there are sufficiently many
implementations. See the section <a href="#exit">“CR exit criteria”
</a> for details.
<p class=mtb>This module should eventually replace corresponding parts
of the revised CSS level 2 specification [[!CSS21]]. But this is an
early draft and any differences to level 2 are most likely
unintentional, unless they concern new features, such as vertical text
or float displacement. <em>Please help us improve the next draft by
pointing out such differences.</em>
<h2 class="no-num no-toc">Table of contents</h2>
<!--toc-->
<h2>How to read this specification</h2>
<p>All sections are normative, unless stated otherwise.
<div class=example>
<p>Examples look like this and normally start with the word
&ldquo;Example.&rdquo; Examples are not normative.
</div>
<p class=note>Notes look like this and normally start with the word
&ldquo;Note.&rdquo; Notes are not normative.
<p class=issue>Editorial notes look like this. They will be removed before
the document becomes Candidate Recommendation.
<p>Each property is defined in part in the text and in part by a table that
groups together a number of A3CA facts about the property, including a regular
expression to restrict its syntax. See <span class=issue>[where?]</span>
for the meaning. The &ldquo;Inherited&rdquo; and &ldquo;Initial&rdquo; rows
in the table are used by the Cascading and Inheritance module [[CSS3CASCADE]]
and &ldquo;Media&rdquo; by the Media Queries specification [[MEDIAQ]].
<p>The specification may refer to the <em>used value</em> and the
<em>computed value</em> of a property. Unless stated explicitly, the
short form “value” means the computed value.
<h2>Dependencies on other modules</h2>
<p>This CSS module depends on the following other CSS modules:
<ul>
<li><cite>CSS Writing Modes Module</cite> [[!CSS3-WRITING-MODES]]
&ndash; switch between vertical and horizontal text, properties
<dfn>writing-mode</dfn> and <dfn>direction</dfn>, definitions of the
terms <dfn>block flow direction</dfn> and <dfn>inline base
direction.</dfn>
<li><cite>CSS Syntax Module</cite> [[!CSS3SYN]] &ndash; syntax of
properties and values
<li><cite>CSS Values and Units Module</cite> [[!CSS3VAL]] &ndash;
definitions of value types <dfn><var>&lt;number&gt;</var></dfn>,
<dfn><var>&lt;percentage&gt;</var></dfn>,
<dfn><var>&lt;angle&gt;</var></dfn> and
<dfn><var>&lt;length&gt;</var></dfn>; defines the terms <dfn>computed
value</dfn> and <dfn>used value.</dfn>
<li><cite>CSS Text Module</cite> [[!CSS3TEXT]] &ndash; inline layout and
definition of <dfn>line box.</dfn>
<li><cite>CSS Generated and Replaced Content module</cite> [[!CSS3GENCON]]
&ndash; defines the terms <dfn>replaced element</dfn>
and <dfn>intrinsic</dfn> size (and intrinsic ratio).
<li><cite>CSS Backgrounds and Borders Module</cite> [[!CSS3BG]] &ndash;
defines <dfn><var>&lt;bg-position&gt;</var></dfn>
<li><cite>CSS Basic User Interface Module</cite> [[!CSS3UI]] &ndash;
defines <dfn>box-sizing</dfn>
<li><cite>CSS 2D Transforms</cite> [[!CSS3-2D-TRANSFORMS]] &ndash;
defines <dfn>transform</dfn>
</ul>
<h2>Introduction &amp; definitions</h2>
<p class=issue>Investigate if it is possible to make a pseudo-element
to select anonymous boxes ('::paragraph'). See minutes of 10 Aug 2011.
<p class=note>Note: The model in this specification differs from the
model described in the CSS level 2 specification [[!CSS21]], because
it is generalized to apply also to vertical text.
<p>CSS assumes that the document to lay out is modeled as a <span
class=index title="tree!!of elements|document tree|element
tree">tree</span> of <dfn title="element">elements.</dfn> Each element
has an ordered list of zero or more child elements, with an optional
string of text before the list, in-between the children and after the
list. Each child has one parent, except for the unique element that
has no parent, which is called the <dfn>root element.</dfn>
<p>CSS describes how each element and each string of text is laid out
by transforming the document tree into a set of rectangular boxes,
whose size, position, and stacking level on the <em>canvas</em> depend
on their properties. We say that an element <dfn title="generated
box">generates</dfn> one or more boxes. There are <em>block-level</em>
boxes, <em title="line box">line boxes</em> and <em
title="inline-level">inline-level boxes.</em> A block-level box is
like a paragraph. A line box is like a line of text. Inline-level
boxes are like words inside a line.
<p>When the specification says a box <var>A</var> <dfn>contains</dfn>
a box <var>B</var>, then <var>B</var> is a box generated by an element
that is a descendant of the element that generated
<var>A</var>. Typically, box <var>B</var> is geometrically
contained in box <var>A</var> as well, but that need not be the case,
because of, e.g., overflow or negative margins.
<p class=note>Note: The precise rules are below and in other modules, but in
summary, a block-level box contains either other block-level boxes (e.g., a
section containing paragraphs, or a table containing rows), or it contains
line boxes (e.g., a paragraph containing lines of text). A line box contains
inline-level boxes (e.g., a line with words in different styles). An
inline-level box may contain either text interspersed with more inline-level
boxes, or it may contain a block-level box (e.g., a small table that is
rendered inline).
<div class=figure>
<p><img src="box-intro.png" alt="Schematic representation of rel">
<p class="caption">Relation between four displayed boxes in the
rendered document (on the right) and the three corresponding
elements in the source document on the (left).
</div>
<div class=example>
<p>For example, a fragment of HTML such as
<pre>&lt;ul&gt;
&lt;li&gt;The first item in the list.
&lt;li&gt;The second item.
&lt;/ul&gt;</pre>
<p>may result in one block-level box for the <code>ul</code> element,
containing two block-level boxes for the two <code>li</code> elements, each
of which has one line box (i.e., one line of text). Both line boxes contain
two inline-level boxes: one that contains the list bullet and one that
contains the text.
<p>Note how the <code>li</code> is transformed into multiple boxes, including
one that contains &ldquo;generated content,&rdquo; viz., the list bullet,
which is not present in the source document.
<p>If the document is rendered in a narrow window, it may be that the
<code>li</code> elements get transformed into even more boxes, because the
text requires multiple lines. And if the document is rendered on paper, it
may be that a page break falls in the middle of the <code>ul</code> element,
so that it is not transformed into a single block-level box, but into two
smaller ones, each on a different page.
</div>
<p>Each box belongs to exactly one element. It is either <span
title="generated box">generated</span> directly by the element, or it
is an <em>anonymous box</em> (defined below), which is inserted
because the layout rules of CSS require a box to contain a certain
kind of other box, but the boxes generated by the child elements are
not of that kind. The anonymous box is defined to belong to the
parent.
<p class=note>Note: This is mainly important for <span
class=index>WYSIWYG document editors</span>: if the user selects a box
on the screen in order to set a property, the editor knows which
element to set the property on.
<p>Properties are set on elements and influence how the element is turned
into boxes, but in this specification we refer interchangeably to &ldquo;the
<var>P</var> property of an element&rdquo; and &ldquo;the <var>P</var>
property of a box&rdquo; (both of which actually mean &ldquo;<em>the
value</em> of property <var>P</var> of&hellip;&rdquo;), unless it is
important to distinguish the box and the element, e.g., because the element
has several boxes and they don't all have the same value for the property.
<div class=figure id=various>
<p><img src="box.png" alt="Diagram of a typical box, showing the
content, padding, border and margin areas">
<p class="caption">The various areas and edges of a typical box
</div>
<p>Boxes have padding, a border and margins (see the <a
href="#various">figure</a>). Different properties determine the
thickness of each of these (which may be zero). The margins are also
subject to <em title="collapse">collapsing.</em>
<p>Each box has a <dfn>content area</dfn> (a.k.a. <dfn>content
box</dfn>). The rectangle that bounds this area is the <dfn>content
edge.</dfn> Around the content area is the <dfn>padding area</dfn> and
its outside bounds are called the <dfn>padding edge.</dfn> The padding
area and content area together form the <dfn>padding box.</dfn>
Outside the padding is the <dfn>border area</dfn> and the outside
boundary of that area is the <dfn>border edge.</dfn> The border area,
padding area and content area together form the <dfn>border box.</dfn>
Finally, outside the border is the <dfn>margin area</dfn> and its
outer edge is the <dfn>margin edge.</dfn>
<p>When the specification says that the padding or border is
&ldquo;absent&rdquo; on some side of the box, that actually means that its
thickness is zero.
<p><em title="line box">Line boxes</em> cannot have any padding,
border or margin, and therefore their margin edge, border edge,
padding edge and content edge all coincide.
<p class=note>Note that the margin, unlike the border and padding, may have
a negative thickness. That is one way to make adjacent boxes overlap each
other.
<p class=note>Note that the edges always form rectangles, even if
there is a 'border-radius' [[CSS3BG]] or a shape [[CSS3-EXCLUSIONS]].
<p>A box or element is <dfn>horizontal</dfn> if its 'writing-mode'
property is ''horizontal-tb'', otherwise it is <dfn>vertical.</dfn>
The <dfn>orientation</dfn> of a box or element is the pair of values
of its 'writing-mode' and 'direction'
<div class=note>
<p>Note that there are theoretically eight possible orientations, but
CSS only defines six:
<table class=equiv-table>
<thead>
<tr>
<th>
<th>'writing-mode: horizontal-tb'
<th>'writing-mode: vertical-rl'
<th>'writing-mode: vertical-lr'
<tbody>
<tr>
<th>'direction: ltr'
<td>
<p>Text is written from left to right and paragraphs
grow downwards <p><img class=small
src="horizontal.png" alt="">
<td>
<p>Text is written top to bottom and paragraphs grow to
the left <p><img class=small src="vertical-rl.png"
alt="">
<td>
<p>Text is written top to bottom and paragraphs grow to
the right <p><img class=small src="vertical-lr.png"
alt="">
<tr>
<th>'direction: rtl'
<td>
<p>Text is written from right to left and paragraphs
grow downwards
<td>
<p>Text is written bottom to top and paragraphs grow to
the left
<td>
<p>Text is written bottom to top and paragraphs grow to
the right
</table>
<p>There is no “horizontal-bt.”
</div>
<p>This specification sometimes refers to abstract edges
<dfn>head,</dfn> <dfn>end,</dfn> <dfn>tail</dfn> and <dfn>start,</dfn>
which are relative to the orientation of a box. They map to top,
right, bottom and left as follows:
<table class=equiv-table>
<thead>
<tr>
<th>Value of 'writing-mode'
<th>Value of 'direction'
<th>Meaning of “head”
<th>Meaning of “end”
<th>Meaning of “tail”
<th>Meaning of “start”
<tbody>
<tr><th>''horizontal-tb'' <th>''ltr''
<td>top <td>right <td>bottom <td>left
<tr><th>''horizontal-tb'' <th>''rtl''
<td>top <td>left <td>bottom <td>right
<tr><th>''vertical-rl'' <th>''ltr''
<td>right <td>bottom <td>left <td>top
<tr><th>''vertical-rl'' <th>''rtl''
<td>right <td>top <td>left <td>bottom
<tr><th>''vertical-lr'' <th>''rtl''
<td>left <td>bottom <td>right <td>top
<tr><th>''vertical-lr'' <th>''ltr''
<td>left <td>top <td>right <td>bottom
</table>
<p>For example, the “head padding” by default refers to the
'padding-top' and the “end border” is by default the 'border-right'.
<div class=issue>
<p>[Alternative terminology:]
<p>This specification sometimes refers to abstract edges
<dfn>A,</dfn> <dfn>B,</dfn> <dfn>C</dfn> and <dfn>D,</dfn>
which are relative to the orientation of a box. They map to top,
right, bottom and left as follows:
<table class=equiv-table>
<thead>
<tr>
<th>Value of 'writing-mode'
<th>Value of 'direction'
<th>Meaning of “A”
<th>Meaning of “B”
<th>Meaning of “C”
<th>Meaning of “D”
<tbody>
<tr><th>''horizontal-tb'' <th>''ltr''
<td>top <td>right <td>bottom <td>left
<tr><th>''horizontal-tb'' <th>''rtl''
<td>top <td>left <td>bottom <td>right
<tr><th>''vertical-rl'' <th>''ltr''
<td>right <td>bottom <td>left <td>top
<tr><th>''vertical-rl'' <th>''rtl''
<td>right <td>top <td>left <td>bottom
<tr><th>''vertical-lr'' <th>''rtl''
<td>left <td>bottom <td>right <td>top
<tr><th>''vertical-lr'' <th>''ltr''
<td>left <td>top <td>right <td>bottom
</table>
<p>For example, the “A padding” by default refers to the
'padding-top' and the “B border” is by default the 'border-right'.
</div>
<p>Similarly, the specification sometimes refers to the
<dfn title="inline dimension">inline</dfn> and <dfn title="block flow
dimension">block flow</dfn> dimensions of a box, instead of width and
height, as follows:
<table class=equiv-table>
<tr>
<th>Writing mode
<th>Meaning of “inline dimension”
<th>Meaning of “block flow dimension”
<tr><td><span>horizontal</span> <td>width <td>height
<tr><td><span>vertical</span> <td>height <td>width
</table>
<p>These correspond to the dimensions in the <em>inline base
direction</em> and the <em>block flow direction,</em> respectively.
<div class=issue>
<p>[Alternative terminology:]
<p>Similarly, the specification sometimes refers to the <dfn>B-D</dfn>
and <dfn>A-C</dfn> dimensions of a box, instead of width and height,
as follows:
<table class=equiv-table>
<tr>
<th>Writing mode
<th>Meaning of “B-D”
<th>Meaning of “A-C”
<tr><td><span>horizontal</span> <td>width <td>height
<tr><td><span>vertical</span> <td>height <td>width
</table>
<p>These correspond to the dimensions in the <em>inline base
direction</em> and the <em>block flow direction,</em> respectively.
</div>
<p>Finally, the <dfn>headside,</dfn> <dfn>endside,</dfn>
<dfn>tailside</dfn> and <dfn>startside</dfn> of a box are defined as
the sides that correspond to the <em>head,</em> <em>end,</em>
<em>tail</em> and <em>start,</em> of the <em>containing block</em> of
the box.
<div class=example>
<p>For example, if a box has a 'writing-mode' of ''horizontal-tb'',
then its top content edge acts as its <em>head</em> content edge,
and the <em>headside</em> edges of its children are therefore their
top edges, independent of what their own 'writing-mode' is.
<div class=figure>
<p><img src="headside" alt="[Figure: the “head content edge” of
the child box the right edge, but the“headside content edge” is
the top.]">
<p class=caption>The second child box is a vertical box and has
its “head” content edge on the right. But its “headside”
content edge is at the top.
</div>
</div>
<div class=issue>
<p>[Alternative terminology:]
<p>Finally, the <dfn>A&prime;,</dfn> <dfn>B&prime;,</dfn>
<dfn>C&prime;</dfn> and <dfn>D&prime;</dfn> sides of a box are defined
as the sides that correspond to the <em>A,</em> <em>B,</em> <em>C</em>
and <em>D</em> sides of the <em>containing block</em> of the box.
<div class=example>
<p>For example, if a box has a 'writing-mode' of ''horizontal-tb'',
then its top content edge acts as its <em>A</em> content edge, and
the <em>A&prime;</em> edges of its children are therefore their top
edges, independent of what their own 'writing-mode' is.
<div class=figure>
<p><img src="headside" alt="[Figure: the “A content edge” of
the child box the right edge, but the “A&prime; content edge” is
the top.]">
<p class=caption>The second child box is a vertical box and has
its “A” content edge on the right. But its “A&prime;” content edge
is at the top.
</div>
</div><!-- /figure -->
</div><!-- /example -->
</div><!-- /issue -->
<p class=issue>Check terms. At Cambridge ftf Aug 2008 we chose:
Property name: block-flow with values tb | lr | rl | bt. Descriptive
terms: horizontal mode (= tb &amp; bt), vertical mode (= lr &amp;
rl). The May 2012 Writing Modes module now has 'writing-mode' with
values ''horizontal-tb'', ''vertical-rl'' and ''vertical-lr'' (and no
''bt'' anymore).
<h2>The viewport and the canvas</h2>
<p>User agents for continuous media generally offer users a
<dfn>viewport</dfn> (a window or other viewing area on the screen)
through which users consult a document. User agents may change the
document's layout when the viewport is resized (see the <em>initial
containing block</em>).
<p>When the viewport is smaller than the area of the <em>canvas</em>
(see below) on which the document is rendered, the user agent should
offer a scrolling mechanism. There is at most one viewport per canvas,
but user agents may render to more than one canvas (i.e., provide
different views of the same document).
<p>For all media, the term <dfn>canvas</dfn> describes the space where
the formatting structure is rendered. The canvas is infinite for each
dimension of the space.
<h2>Aspect ratios of replaced elements</h2>
<p>For the purposes of the width and height calculations below, CSS
distinguishes four kinds of <em title="replaced element"
class=index>replaced elements</em>:
<dl>
<dt>Type 1: replaced elements with both <em class=index>intrinsic
width</em> and <em class=index>intrinsic height.</em> <dd>These are
replaced elements that are meant to be displayed with a certain fixed
factor (the <em>intrinsic ratio</em>) between their width and height
and also have a default size. Different formats may have different
ways of specifying the size, e.g., a width and a ratio, or a raster
and a resolution in dots per inch. Raster images fall in this
category.
<dt>Type 2: replaced elements with only an <em>intrinsic ratio</em>
<dd>These are replaced elements that are meant to be displayed with a
certain fixed factor between their width and height, but without a
default size. <span class=index>SVG</span> images often fall in the
this category.
<dt>Type 3: replaced elements with a <dfn>complex aspect ratio</dfn>
<dd>These are replaced elements that do not have a <em>fixed</em>
ratio between their width and height, but that do have a functional
relation between them in the sense that for every width there is a
unique height. HTML documents are examples of this: the width can be
chosen freely, but at every width there is a definite intrinsic
height.
<dt>Type 4: replaced elements without an intrinsic ratio <dd>These are
replaced elements that have no relation between their width and
height. Certain <span class=index>SVG</span> images are examples of
this.
</dl>
<p>For <span class=index>raster images</span> without reliable
resolution information, a size of 1 px unit per image source pixel
must be assumed. These images thus are of type 1.
<div class=example>
<p>E.g., in the section on <a href="#inline-replaced">inline replaced
elements,</a> if the replaced element is an HTML document and the
height is specified as ''auto'', e.g.:
<pre>
... &lt;object data="example.html"
style="width: 30em; height: auto">&lt;/object>...
</pre>
<p>then the used height will be 150px, which is unlikely to be the
real height of the example.html document. But if the height is
specified as ''complex'', e.g.:
<pre>
... &lt;object data="example.html"
style="width: 30em; height: complex">&lt;/object>...
</pre>
<p>then the height will be the height the example.html document
normally has when displayed on its own with the given width. This
enables almost seamless integration of external text in a document,
without a scrollbar or similar. (The external text is still displayed
with its own style sheet.)
</div>
<div class=example>
<p>An (external) mathematical formula in MathML is an example of
replaced content with an intrinsic width and height. Assume the file m.mml
contains a formula, then the HTML fragment
<pre>
... derive &lt;img src="m.mml"
alt="that the sum of p(i) for i greater than 0 equals N">
for the case...
</pre>
<p>renders the formula at its intrinsic size.
</div>
<p class=issue>The mathematical formula would however benefit from a
way to negotiate available space against intrinsic size, or even
negotiate available space against the number of boxes, so that the
formula could be broken in two or more boxes and occupy space on two
or more lines (similar to how lines of text are broken or words are
hyphenated). But an easier solution might be to extend HTML with
native support for math and CSS with math boxes, so that replaced
elements remain single boxes.
<h2>Basic flow layout</h2>
<p>As described in the introduction, elements give rise to boxes and
those boxes are laid out on a <em>canvas.</em> Different kinds of
boxes are laid out differently. This section describes the layout of
one <em>flow</em> of boxes.
<p>The approximate model for the layout of a flow of boxes is that
sibling boxes are laid out one after the other in one long series with
margins between them and parent boxes tightly wrap the series of child
boxes. The 'writing-mode' property of the parent determines if that series
grows down (''tb''), to the left (''rl''), to the right (''lr'') or up
(''bt''). Although the rules below depend on terms that are only
defined further down, the rules are given at the outset, to provide at
least an approximate model of how boxes are positioned relative to one
another.
<p>The following rules define the position of <em>block-level</em>
boxes relative to the box that is their <em>flow root.</em> Other
sections and other modules describe how other boxes are laid out.
E.g., floating boxes are described further down in this module and
absolutely positioned boxes are described in the Absolute Positioning
module [[CSS3POS]].
<p>Before applying these rules, the width, height and margins of each
box must be computed as described in the sections <a
href="#Calculating">“Calculating widths, heights and margins”</a>
and <a href="#Collapsing">“Collapsing margins.”</a>
<ul>
<li>
<p>Consider the first box (in document order) of a set of sibling
boxes that all belong to the same flow. There are four cases:
<ol>
<li>
<p>If none of its margins <span>collapse</span> with its
parent's <span>head</span> margin and the box is
not <span>collapsed through,</span> then the box is placed
such that the box's <span>headside</span> <span>margin
edge</span> touches the
parent's <span>head</span> <span>content edge</span>,
the <span>startside</span> <span>margin edge</span> touches
the parent's <span>start</span> <span>content edge</span> and
the <span>endside</span> <span>margin edge</span> touches the
parent's <span>end</span> <span>content edge.</span>
<p class=issue>[Add illustration.]
<p class=issue>[Alternative terminology:] If none of its
margins <span>collapse</span> with its parent's <span>A</span>
margin and the box is not <span>collapsed through,</span> then
the box is placed such that the box's <span>A&prime;</span>
<span>margin edge</span> touches the parent's <span>A</span>
<span>content edge</span>, the <span>D&prime;</span>
<span>margin edge</span> touches the parent's <span>D</span>
<span>content edge</span> and the <span>B&prime;</span>
<span>margin edge</span> touches the parent's <span>B</span>
<span>content edge.</span>
<li>
<p>If none of its margins <span>collapse</span> with its
parent's <span>head</span> margin but the box
is <span>collapsed through,</span> then its <span>content
edge</span> (which is also its <span>border edge</span>
and <span>padding edge</span>) is defined as what it would
have been if the box had a non-zero <span>tailside</span>
border. (I.e., recompute the margins given that border and
then apply the previous rule.)
<p class=note>Note that the box is effectively invisible, but
the edges have to be defined to position any descendants, such
as floating or absolutely positioned children.
<li>
<p>If exactly one of its margins collapses with its
parent's <span>head</span> margin, then the box is placed such
that the box's <span>headside</span> <span>border edge</span>
touches the parent's <span>head</span> <span>content
edge,</span> the <span>startside</span> <span>margin
edge</span> touches the
parent's <span>start</span> <span>content edge</span> and
the <span>endside</span> <span>margin edge</span> touches the
parent's <span>end</span> <span>content edge.</span>
<p class=issue>[Add illustration.]
<li>
<p>If two of its margins collapse with its
parent's <span>head</span> margin, then its position is such
that its <span>content edge</span> (which is also
its <span>border edge</span>) touches its
parent's <span>head</span> <span>border edge</span> and that
its <span>startside</span> <span>margin edge</span> touches
its parent's <span>start</span> <span>content edge</span> and
its <span>endside</span> <span>margin edge</span> touches the
parent's <span>end</span> <span>content edge.</span>
<p class=note>Note that the box is effectively invisible, but
the edges have to be defined to position any descendants.
</ol>
<li>
<p>For a box that has a preceding sibling in the same flow there
are two cases:
<ol>
<li>
<p>If the box is not <span>collapsed through,</span> it is
positioned such that its <span>margin edge</span> touches the
parent's <span>start</span> <span>content edge</span>
and <span>end</span> <span>content edge</span> and such that
its content edge on the touches
the <span class=issue>[...]</span>
<li>
<p>A box that has a preceding sibling in the same flow and that
is <span>collapsed
through,</span> <span class=issue>[...]</span>
</ol>
</ul>
<h2>Types of boxes</h2>
<p>The layout of boxes in the flow is in lar 2334 ge part determined by the
interplay of the 'display' properties of an element and its parent,
and then fine-tuned with margins and padding.
<h3 id=display>The display property</h3>
<table class="propdef">
<tr><td>Name: <td><dfn>display</dfn>
<tr><td>Value: <td>inline | block | inline-block | list-item |
run-in | compact | table | inline-table | table-row-group |
table-header-group | table-footer-group | table-row |
table-column-group | table-column | table-cell | table-caption |
ruby | ruby-base | ruby-text | ruby-base-group | ruby-text-group |
align-box | none
<tr><td>Initial: <td>inline
<tr><td>Applies to:<td>all elements
<tr><td>Inherited: <td>no
<tr><td>Percentages: <td>N/A
<tr><td>Media: <td>visual (''none'' applies to all media)
<tr><td>Computed value: <td>specified value, except for floats, root
elements and positioned elements; see text
</table>
<p class=issue>There is an old proposal to split 'display' into
display-role (the function of the element in its parent) and
display-model (how the element lays out it children). That allows some
combinations that have no keyword, such as a table cell
('display-role: table-cell') that is itself a table ('display-model:
table'), without the need for an extra wrapper element. It allows
certain things (for math layout, e.g.), but is not easy to use. An
alternative proposal is an '::outside' pseudo-element to create an
extra box on which to set a different 'display' value. That is not
easy either, and doesn't cascade well. And a third proposal is to
allow two values on 'display': if there are two (in any order), one is
the role and the other the model, unless the pair makes no sense. That
doesn't make the concept any easier, but it hides the complexity
better.
<p>This property, in combination with 'float' and 'position',
determines the type of box or boxes that are generated for an element.
The values are as follows:
<dl>
<dt>inline <dd>Inline boxes.
<dt>block <dd>Block boxes.
<dt>inline-block <dd>A block box, which itself is flowed as a single
inline box, similar to a replaced element. The inside of an
inline-block is formatted as a block box, and the box itself is
formatted as an inline box.
<dt>list-item <dd>One or more block boxes and one marker box. Marker
boxes are defined in the Lists module [[CSS3LIST]]. <span
class=issue>If the Lists module is not ready, define the position of
the marker and the list-style property here? Or refer to CSS 2.1
instead?</span>
<dt>run-in <dd>Either block or inline boxes, depending on context
(see <a href="#run-in-boxes">Run-in boxes</a>). Properties apply to
run-in boxes based on their final status (<span>inline-level</span>
or <span>block-level</span>).
<dt>compact <dd>Either block boxes or a marker box, depending on
context (see <a href="#compact-boxes">Compact boxes</a>). Properties
apply to compact boxes based on their final status.
<dt>table, inline-table, table-row-group, table-header-group,
table-footer-group, table-row, table-column-group, table-column,
table-cell, table-caption <dd>See the Tables module [[CSS3TBL]].
<dt>ruby, ruby-base, ruby-text, ruby-base-group, ruby-text-group
<dd>See the Ruby module [[CSS3RUBY]].
<dt>align-box <span class=issue>or container?</span> <dd>Like
''block'', but forces the element to be a <em>flow root,</em>,
which, e.g., stops its margins from collapsing with margins of child
elements and includes floating children in its
height. <span class=issue>[C.f.
the <a href="#contain-floats">discussion of how to force an element
to contain floats.</a>]</span>
<dt>none <dd>This value causes an element to not appear in the
formatting structure (i.e., in visual media, the element generates
no boxes and has no effect on layout). Descendant elements do not
generate any boxes either; the element and its content are removed
from the formatting structure entirely. This behavior
<strong>cannot</strong> be overridden by setting the 'display'
property on the descendants.
</dl>
<p class=note>Note that ''none'' does not create an invisible box; it
creates no box at all. See 'visibility' for a mechanisms that enables
an element to generate boxes that affect formatting but are not
visible themselves.
<p class=note>Note that both 'clear-after' and ''align-box'' can be
used to force the next element after this one to start after any
floats inside this element, but the effect is not exactly the same.
E.g., 'display: box' also affects certain forms of margin
collapsing.
<p class=note>Note that 'vertical-al ign' applies to ''align-box''
elements, hence the name. The 'vertical-align' property doesn't apply
to other block-level elements, except ''table-cell'' elements.
<p class=issue>Any sense in vertically spreading out the contents,
something like 'vertical-align: justify'?
<p class=issue>Simpler to not use 'vertical-align', but creating
''top-box'', ''middle-box'' and ''bottom-box''?
<div class=example>
<p>The 'vertical-align' property applies to ''align-box''
elements <span class=issue>[check in [[!CSS3TEXT]]!]</span>, and can
thus be used to create vertically centered content, without wrapping
the content in a table (which may not be always possible, and also
causes the 'width' property to behave differently).
<pre>
div.slide {
display: align-box;
height: 15em;
vertical-align: middle;
border: thin solid }
</pre>
<p>with a document fragment like this:
<pre>
&lt;div class=slide>
&lt;ul>
&lt;li>Bullet lists are boring
&lt;li>They distract from the speaker
&lt;li>Don't use them!
&lt;/ul>
&lt;/div>
</pre>
<p>might look like this figure:
<div class=figure>
<p><img src="align-box.png" alt="A 15 em high box with three bullet
items in the center">
<p class=caption>The 'vertical-align: middle' causes the content of
the ''align-box'' to be vertically centered.
</div>
</div>
<p>The computed value of 'display' depends on 'position' [[CSS3POS]],
'float' and 'overflow':
<ol>
<li>If the specified value of 'display' is ''none'', then the
computed value is ''none'' (and 'overflow', 'float' and 'position'
do not apply).
<li>Otherwise, if 'position' is ''absolute'' or ''fixed'', or if
'float' is not ''none'', or if 'overflow' is not ''visible'', or if
the element is the root element, then the computed value of
'display' is set according to the following table:
<table class=equiv-table>
<thead>
<tr><th>Specified value <th>Computed value
<tbody>
<tr><td>inline-table <td>table
<tr><td>inline, run-in, table-row-group,
table-column, table-column-group,
table-header-group, table-footer-group,
table-row, table-cell, table-caption,
inline-block <td>block
<tr><td>others <td>same as specified
</table>
<li>Otherwise, the computed value of 'display' is the same as the
specified value.
</ol>
<h3>Mixing the box model with other formatting models</h3>
<p>There may be documents that combine different layout models, such
as documents that combine HTML (typically rendered with the CSS box
model) and <span class=index>SVG</span> (rendered with its own
graphics model). If an element that is rendered according to the CSS
box model has a child that is to be rendered with a different model,
that child needs to have a 'display' property with a value that
indicates that the child is not in the box model.
<p>Such a child is treated as a <em>replaced element</em> for the
purposes of determining its size, position, margins, padding and
border.
<p class=issue>Should we allow a more complex model, where such a
child may negotiate with the CSS environment to have several boxes and
several baselines, so that it can take part in line breaking and page
breaking?
<p>This specification defines no value(s) for the 'display' property
that indicate that an element is formatted according to a different
model than the box model, but separate specifications may do so.
<h3>Block-level boxes, containing blocks, flows and anonymous
boxes</h3>
<p>A <dfn>block-level</dfn> box is a box that has a <span>computed
value</span> for 'display' of ''block'', ''align-box'', ''list-item'',
''table'', ''table-*'' (i.e., all table boxes, see [[CSS3TBL]]),
''run-in'' (under
certain circumstances, see <a href="#run-in-boxes">“Run-in boxes”
</a>), or ''compact'' (under certain circumstances, see <a
href="#compact-boxes">“Compact boxes”</a>).
<p>An <dfn>inline-level</dfn> box is a box that has a <span>computed
value</span> for 'display' of ''inline'', ''inline-block'',
''inline-table'', ''ruby'', ''run-in'' (under certain circumstances),
or ''compact'' (under certain circumstances).
<p class=issue>[What about the other ruby values?]
<p>An <dfn>anonymous box,</dfn> informally, is a box that cannot be addressed
with CSS selectors. All its properties, except for 'display', have their
default values (either the initial value or inherited). Anonymous boxes are
created when the CSS box model requires a child box with a certain value for
'display', but the child actually has a different value. In that case an
anonymous box of the right kind is created and wraps the child (or children).
Other modules (e.g., [[CSS3TBL]], [[!CSS3TEXT]]) may also define anonymous
boxes. The anonymous boxes defined by this module are the following:
<ul>
<!--
<li>An ''inline-table'' element creates one box with ''inline-table'' as
the value for 'display', which contains one anonymous box with ''table''
as the value.
<li>An ''inline-block'' element creates one box with ''inline-block'' as
the value for 'display', containing one anonymous box with ''block'' as
the value.
<li>A <span>block-level</span> element that has a
'writing-mode' of ''lr'' or
''rl'' and a parent with a 'writing-mode' of ''tb'' (or vice-versa)
generates one or more block-level boxes with the same 'writing-mode'
as the parent, each of which has one anonymous child box with a 'display'
of ''block'' and the 'writing-mode' of the element itself. <span
class=issue>[Coordinate this with CSS3-WRITING-MODES]</span>
-->
<li>A <span>block-level box</span> may contain either <span
title="line box">line boxes</span> or <span>block-level</span>
boxes, but not both. If
necessary, any line boxes that belong to this box's element are wrapped
in one or more (as few as possible) anonymous boxes with a 'display' of
''block''.
</ul>
<div class=example>
<p>An example of the last point above is this document fragment:
<pre>&lt;p&gt;Somebody whose name I have
forgotten, said, long ago: &lt;q&gt;a box is
a box,&lt;/q&gt; and he probably meant it.&lt;/p&gt;</pre>
<p>with these style rules: