8000 csswg-drafts/css2/visudet.html at b395796ed32f44ff6b31b244b618e3730512768e · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1690 lines (1465 loc) · 87.7 KB

File metadata and controls

1690 lines (1465 loc) · 87.7 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Visual formatting model details</title>
<link rel="stylesheet" href="style/default.css" type="text/css">
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" type="text/css">
<link rel="prev" href="visuren.html">
<link rel="next" href="visufx.html">
<link rel="contents" href="cover.html#minitoc">
<link rel="CSS-properties" href="propidx.html" title="properties">
<link rel="index" href="indexlist.html" title="index">
<link rel="first" href="cover.html">
<style type="text/css">
.current,.proposed,span.delcurrent,div.delcurrent { background:#feb }
ins.proposed,span.insproposed,li.insproposed,div.insproposed { background:#bfb }
del.proposed,span.delproposed { background:#fbb }
span.insproposed,li.insproposed,div.insproposed { text-decoration:underline }
span.delproposed,span.delcurrent,div.delcurrent { text-decoration:line-through }
body>del,body>ins {display:block}
</style>
</head>
<body>
<div class="navbar">
<p><a href="visuren.html">previous</a> &nbsp;
<a href="visufx.html">next</a> &nbsp;
<a href="cover.html#minitoc">contents</a> &nbsp;
<a href="propidx.html">properties</a> &nbsp;
<a href="indexlist.html">index</a> &nbsp;
</div>
<hr class="navbar">
<h1><a name="q0">10 Visual formatting model details</a></h1>
<div class="subtoc">
<p><strong>Contents</strong>
<ul class="toc">
<li class="tocline2"><a href="visudet.html#containing-block-details" class="tocxref">10.1 Definition of "containing block"</a>
<li class="tocline2"><a href="visudet.html#the-width-property" class="tocxref">10.2 Content width: the <span class="propinst-width">'width'</span> property</a>
<li class="tocline2"><a href="visudet.html#Computing_widths_and_margins" class="tocxref">10.3 Calculating widths and margins</a>
<ul class="toc">
<li class="tocline3"><a href="visudet.html#inline-width" class="tocxref">10.3.1 Inline, non-replaced elements</a>
<li class="tocline3"><a href="visudet.html#inline-replaced-width" class="tocxref">10.3.2 Inline, replaced elements</a>
<li class="tocline3"><a href="visudet.html#blockwidth" class="tocxref">10.3.3 Block-level, non-replaced elements in normal flow</a>
<li class="tocline3"><a href="visudet.html#block-replaced-width" class="tocxref">10.3.4 Block-level, replaced elements in normal flow</a>
<li class="tocline3"><a href="visudet.html#float-width" class="tocxref">10.3.5 Floating, non-replaced elements</a>
<li class="tocline3"><a href="visudet.html#float-replaced-width" class="tocxref">10.3.6 Floating, replaced elements</a>
<li class="tocline3"><a href="visudet.html#abs-non-replaced-width" class="tocxref">10.3.7 Absolutely positioned, non-replaced elements</a>
<li class="tocline3"><a href="visudet.html#abs-replaced-width" class="tocxref">10.3.8 Absolutely positioned, replaced elements</a>
<li class="tocline3"><a href="visudet.html#inlineblock-width" class="tocxref">10.3.9 'Inline-block', non-replaced elements in normal flow</a>
<li class="tocline3"><a href="visudet.html#inlineblock-replaced-width" class="tocxref">10.3.10 'Inline-block', replaced elements in normal flow</a>
</ul>
<li class="tocline2"><a href="visudet.html#min-max-widths" class="tocxref">10.4 Minimum and maximum widths: <span class="propinst-min-width">'min-width'</span> and <span class="propinst-max-width">'max-width'</span></a>
<li class="tocline2"><a href="visudet.html#the-height-property" class="tocxref">10.5 Content height: the <span class="propinst-height">'height'</span> property</a>
<li class="tocline2"><a href="visudet.html#Computing_heights_and_margins" class="tocxref">10.6 Calculating heights and margins</a>
<ul class="toc">
<li class="tocline3"><a href="visudet.html#inline-non-replaced" class="tocxref">10.6.1 Inline, non-replaced elements</a>
<li class="tocline3"><a href="visudet.html#inline-replaced-height" class="tocxref">10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements</a>
<li class="tocline3"><a href="visudet.html#normal-block" class="tocxref">10.6.3 Block-level non-replaced elements in normal flow when 'overflow' computes to 'visible'</a>
<li class="tocline3"><a href="visudet.html#abs-non-replaced-height" class="tocxref">10.6.4 Absolutely positioned, non-replaced elements</a>
<li class="tocline3"><a href="visudet.html#abs-replaced-height" class="tocxref">10.6.5 Absolutely positioned, replaced elements</a>
<li class="tocline3"><a href="visudet.html#block-root-margin" class="tocxref">10.6.6 Complicated cases</a>
<li class="tocline3"><a href="visudet.html#root-height" class="tocxref">10.6.7 'Auto' heights for block formatting context roots</a>
</ul>
<li class="tocline2"><a href="visudet.html#min-max-heights" class="tocxref">10.7 Minimum and maximum heights: <span class="propinst-min-height">'min-height'</span> and <span class="propinst-max-height">'max-height'</span></a>
<li class="tocline2"><a href="visudet.html#line-height" class="tocxref">10.8 Line height calculations: the <span class="propinst-line-height">'line-height'</span> and <span class="propinst-vertical-align">'vertical-align'</span> properties</a>
<ul class="toc">
<li class="tocline3"><a href="visudet.html#leading" class="tocxref">10.8.1 Leading and half-leading</a>
</ul>
</ul>
</div>
<h2>10.1 <a name="containing-block-details">Definition of "containing
block"</a></h2>
<p>The position and size of an element's box(es) are sometimes
calculated relative to a certain rectangle, called the <dfn><a name="x0"><span
class="index-def" title="containing block">containing
block</span></a></dfn> of the element. The containing block of an element
is defined as follows:</p>
<ol>
<li>The containing block in which the <a href="conform.html#root">root
element</a> lives is a rectangle called the <dfn><a name="x1"><span
class="index-def" title="initial containing block|containing
block::initial">initial containing block</span></a></dfn>. For continuous
media, it has the dimensions of the <a
href="visuren.html#viewport">viewport</a> and is anchored at the
canvas origin; it is the <a href="page.html#page-area">page area</a>
for paged media. The 'direction' property of the initial
containing block is the same as for the root element.
</li>
<li>For other elements, if the element's position is 'relative' or 'static',
the containing block is formed by the content edge of the nearest
ancestor box that is a <a href="visuren.html#block-boxes">block
container</a> or which establishes a formatting context.
</li>
<li>If the element has 'position: fixed', the containing block is
established by the <a href="visuren.html#viewport">viewport</a>
in the case of continuous media or the page area in the case of paged media.
</li>
<li>If the element has 'position: absolute', the containing block is
established by the nearest ancestor with a <a href="visuren.html#propdef-position" class="noxref"><span
class="propinst-position">'position'</span></a> of 'absolute', 'relative'
or 'fixed', in the following way:
<ol>
<li>In the case that the ancestor is an inline element, the containing
block is the bounding box around the padding boxes of the first and
the last inline boxes
generated for that element. In CSS&nbsp;2.1, if the inline
element is split
across multiple lines, the containing block is undefined.
</li>
<li>Otherwise, the containing block
is formed by the <a href="box.html#padding-edge">padding edge</a> of
the ancestor.
</li>
</ol>
<p>If there is no such ancestor, the containing block is the initial
containing block.
</p>
</li>
</ol>
<p>In paged media, an absolutely positioned element is positioned
relative to its containing block ignoring any page breaks (as if the
document were continuous). The element may subsequently be broken over
several pages.
</p>
<p>For absolutely positioned content that resolves to a position on a
page other than the page being laid out (the current page), or
resolves to a position on the current page which has already been
rendered for printing, printers may place the content
<ul>
<li>on another location on the current page,
<li>on a subsequent page, or
<li>may omit it.
</ul>
<p class="note">Note that a
block-level element that is split over several pages may have a different
width on each page and that there may be device-specific limits.
</p>
<div class="example"><P style="display:none">Example(s):</P>
<p>With no positioning, the containing blocks (C.B.) in the
following document:</p>
<pre class="html-example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Illustration of containing blocks&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY id="body"&gt;
&lt;DIV id="div1"&gt;
&lt;P id="p1"&gt;This is text in the first paragraph...&lt;/P&gt;
&lt;P id="p2"&gt;This is text &lt;EM id="em1"&gt; in the
&lt;STRONG id="strong1"&gt;second&lt;/STRONG&gt; paragraph.&lt;/EM&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
<p>are established as follows:</p>
<table border="1">
<tr><th>For box generated by </th>
<td><strong>C.B. is established by</strong></td></tr>
<tr><td>html</td><td>initial C.B. (UA-dependent)</td></tr>
<tr><td>body</td><td>html</td></tr>
<tr><td>div1</td><td>body</td></tr>
<tr><td>p1</td><td>div1</td></tr>
<tr><td>p2</td><td>div1</td></tr>
<tr><td>em1</td><td>p2</td></tr>
<tr><td>strong1</td><td>p2</td></tr>
</table>
<p>If we position "div1":</p>
<pre class="example">
#div1 { position: absolute; left: 50px; top: 50px }
</pre>
<p>its containing block is no longer "body"; it becomes
the initial containing block (since there are no
other positioned ancestor boxes).
</p>
<p>If we position "em1" as well:</p>
<pre class="example">
#div1 { position: absolute; left: 50px; top: 50px }
#em1 { position: absolute; left: 100px; top: 100px }
</pre>
<p>the table of containing blocks becomes:</p>
<table border="1">
<tr><th>For box generated by</th>
<td><strong>C.B. is established by</strong></td></tr>
<tr><td>html</td><td>initial C.B. (UA-dependent)</td></tr>
<tr><td>body</td><td>html</td></tr>
<tr><td>div1</td><td>initial C.B.</td></tr>
<tr><td>p1</td><td>div1</td></tr>
<tr><td>p2</td><td>div1</td></tr>
<tr><td>em1</td><td>div1</td></tr>
<tr><td>strong1</td><td>em1</td></tr>
</table>
<p>By positioning "em1", its containing block becomes
the nearest positioned ancestor box (i.e., that generated
by "div1").
</p>
</div>
<h2>10.2 <a name="the-width-property">Content width</a>: the <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> property</h2>
<div class="propdef">
<dl><dt>
<span class="index-def" title="'width'"><a name="propdef-width" class="propdef-title"><strong>'width'</strong></a></span>
<dd>
<table class="propinfo" cellspacing=0 cellpadding=0>
<tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length">&lt;length&gt;</span></a> | <a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage">&lt;percentage&gt;</span></a> | auto | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a>
<tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>auto
<tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements but non-replaced inline elements, table rows, and row groups
<tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no
<tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage or 'auto' as specified or the absolute length
</table>
</dl>
</div>
<p> This property specifies the <a
href="box.html#content-width">content width</a> of boxes.
</p>
<p>This property does not apply to non-replaced <a
href="visuren.html#inline-boxes">inline</a> elements. The
content width
of a non-replaced inline element's boxes is that of the rendered
content within them (<em>before</em> any relative offset of
children). Recall that inline boxes flow into <a
href="visuren.html#line-box">line boxes</a>. The width of line boxes
is given by the their <a
href="visuren.html#containing-block">containing block</a>, but may be
shorted by the presence of <a href="visuren.html#floats">floats</a>.
</p>
<p>Values have the following meanings:</p>
<dl>
<dt><span class="index-inst" title="&lt;length&gt;"><a name="x4" href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><strong>&lt;length&gt;</strong></span></a></span>
</dt>
<dd>Specifies the width of the content area using a length unit.
</dd>
<dt><span class="index-inst" title="&lt;percentage&gt;"><a name="x5" href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span></a></span>
</dt>
<dd>Specifies a percentage width. The percentage is calculated
with respect to the width of the generated box's
<a href="visuren.html#containing-block">containing block</a>.
If the containing block's width depends on this element's width, then
the resulting layout is undefined in CSS 2.1.
<span class="note">
Note: For absolutely positioned elements whose containing block is
based on a block container element, the percentage is calculated with
respect to the width of the <em>padding box</em> of that element.
This is a change from CSS1, where the percentage width was always
calculated with respect to the <em>content box</em> of the parent
element.
</span>
</dd>
<dt><strong>auto</strong>
</dt>
<dd>The width depends on the values of other properties.
See the sections below.
</dd>
</dl>
<p>Negative values for <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> are
illegal.
</p>
<div class="example"><P style="display:none">Example(s):</P><p>
For example, the following rule fixes the content width of paragraphs
at 100 pixels:</p>
<pre>
p { width: 100px }
</pre>
</div>
<h2>10.3 <a name="Computing_widths_and_margins">Calculating widths and
margins</a></h2>
<p>The values of an element's <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a>, <a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a>, <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a>, <a href="visuren.html#propdef-left" class="noxref"><span
class="propinst-left">'left'</span></a> and <a href="visuren.html#propdef-right" class="noxref"><span
class="propinst-right">'right'</span></a> properties as used for layout
depend on the type of box generated and on each other. (The value used
for layout is sometimes referred to as the <a
href="cascade.html#usedValue">used value</a>.) In
principle, the values used are the same as the computed values, with
'auto' replaced by some suitable value, and percentages calculated
based on the containing block, but there are exceptions. The following
situations need to be distinguished:</p>
<ol>
<li>inline, non-replaced elements</li>
<li>inline, replaced elements</li>
<li>block-level, non-replaced elements in normal flow</li>
<li>block-level, replaced elements in normal flow</li>
<li>floating, non-replaced elements</li>
<li>floating, replaced elements</li>
<li>absolutely positioned, non-replaced elements</li>
<li>absolutely positioned, replaced elements</li>
<li>'inline-block', non-replaced elements in normal flow</li>
<li>'inline-block', replaced elements in normal flow</li>
</ol>
<p>For Points 1-6 and 9-10, the values of 'left' and 'right' in the
case of relatively positioned elements are determined by the rules in <a
href="visuren.html#relative-positioning">section 9.4.3.</a>
</p>
<p class=note><em><strong>Note.</strong> The used value of 'width'
calculated below is a tentative value, and may have to be calculated
multiple times, depending on <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a> and <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a>, see the section <a
href="#min-max-widths">Minimum and maximum widths</a> below.</em>
<h3>10.3.1 <a name="inline-width">Inline, non-replaced elements</a></h3>
<p>The <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> property does not
apply. A computed value of 'auto' for <a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a> or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> becomes a used
value of '0'.
</p>
<h3>10.3.2 <a name="inline-replaced-width">Inline, replaced elements</a></h3>
<p>A computed value of 'auto' for <a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a> or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> becomes a used
value of '0'.
<p>If <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> and <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> both have computed values of
'auto' and the element also has an intrinsic width, then that
intrinsic width is the used value of <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a>.
<p>If <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> and <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> both have computed values of
'auto' and the element has no intrinsic width, but does have an
intrinsic height and intrinsic ratio; or if <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> has a computed value of 'auto',
<a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> has some other computed
value, and the element does have an intrinsic ratio; then the used
value of <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> is:
<blockquote><p>(used height) * (intrinsic ratio)</blockquote>
<p>If 'height' and <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> both
have computed values of 'auto' and the element has an intrinsic ratio
but no intrinsic height or width, then the used value of 'width' is
undefined in CSS&nbsp;2.1.
However, it is suggested that, if the containing block's width
does not itself depend on the replaced element's width, then the used
value of 'width' is calculated from the constraint equation used for
block-level, non-replaced elements in normal flow.
<p>Otherwise, if <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> has a
computed value of 'auto', and the element has an intrinsic width, then
that intrinsic width is the used value of <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a>.
<p>Otherwise, if <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> has a
computed value of 'auto', but none of the conditions above are met,
then the used value of <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a>
becomes 300px. If 300px is too wide to fit the device, UAs should use
the width of the largest rectangle that has a 2:1 ratio and fits the
device instead.
<h3>10.3.3 <a name="blockwidth">Block-level, non-replaced elements in normal
flow</a></h3>
<p>The following <a name="width-constraints">constraints</a> must hold
among the used values of the other properties:</p>
<blockquote>
<p><a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> + <a href="box.html#propdef-border-left-width" class="noxref"><span
class="propinst-border-left-width">'border-left-width'</span></a> + <a href="box.html#propdef-padding-left" class="noxref"><span
class="propinst-padding-left">'padding-left'</span></a> + <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> + <a href="box.html#propdef-padding-right" class="noxref"><span
class="propinst-padding-right">'padding-right'</span></a> + <a href="box.html#propdef-border-right-width" class="noxref"><span
class="propinst-border-right-width">'border-right-width'</span></a> +
<a href="box.html#propdef-margin-right" class="noxref"><span class="propinst-margin-right">'margin-right'</span></a> = width of <a
href="#containing-block-details">containing block</a>
</p>
</blockquote>
<p>If 'width' is not 'auto' and 'border-left-width' + 'padding-left' +
'width' + 'padding-right' + 'border-right-width' (plus any of
'margin-left' or 'margin-right' that are not 'auto') is larger than
the width of the containing block, then any 'auto' values for
'margin-left' or 'margin-right' are, for the following rules, treated
as zero.
</p>
<p>If
all of the above have a computed value other than 'auto', the values
are said to be "over-constrained" and one of the used values will
have to be different from its computed value. If the <a href="visuren.html#propdef-direction" class="noxref"><span
class="propinst-direction">'direction'</span></a>
property of the containing block has the value 'ltr', the specified
value of <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> is ignored and the
value is calculated so as to make the equality true. If the value of
<a href="visuren.html#propdef-direction" class="noxref"><span class="propinst-direction">'direction'</span></a> is 'rtl', this
happens to <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> instead.
</p>
<p>If there is exactly one value specified as 'auto', its used
value follows from the equality.
</p>
<p>If <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> is set to 'auto',
any other 'auto' values become '0' and <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> follows from the resulting
equality.
</p>
<p>If both <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> and
<a href="box.html#propdef-margin-right" class="noxref"><span class="propinst-margin-right">'margin-right'</span></a> are 'auto',
their used values are equal. This horizontally centers the element
with respect to the edges of the containing block.
</p>
<h3>10.3.4 <a name="block-replaced-width">Block-level, replaced elements in normal flow</a></h3>
<p>The used value of
<a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> is determined
as for <a href="#inline-replaced-width">inline replaced
elements</a>.
Then the rules <a href="#blockwidth">for non-replaced
block-level elements</a> are applied to determine the margins.
</p>
<h3>10.3.5 <a name="float-width">Floating, non-replaced elements</a></h3>
<p>If <a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a>, or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> are computed as
'auto', their used value is '0'.
</p>
<p>If <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> is computed as
'auto', the used value is the "shrink-to-fit" width.
</p>
<p><a name="shrink-to-fit-float"></a> Calculation of the shrink-to-fit
width is similar to calculating the width of a table cell using the
automatic table layout algorithm. Roughly: calculate the preferred
width by formatting the content without breaking lines other than
where explicit line breaks occur, and also calculate the preferred
<em>minimum</em> width, e.g., by trying all possible line breaks.
CSS&nbsp;2.1 does not define the exact algorithm. Thirdly, find the
<em>available width</em>: in this case, this is the width of the
containing block minus the used values of 'margin-left',
'border-left-width', 'padding-left', 'padding-right',
'border-right-width', 'margin-right', and the widths of any relevant
scroll bars.
</p>
<p>Then the shrink-to-fit width is: min(max(preferred minimum width,
available width), preferred width).</p>
<h3>10.3.6 <a name="float-replaced-width">Floating, replaced elements</a></h3>
<p>If <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> are computed as
'auto', their used value is '0'. The used value of <a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> is determined as for <a
href="#inline-replaced-width">inline replaced elements</a>.
</p>
<h3>10.3.7 <a name="abs-non-replaced-width">Absolutely positioned, non-replaced elements</a></h3>
<p>For the purposes of this section and the next, the term <a
name=static-position><span class=index>"static position"</span></a>
(of an element) refers, roughly,
to the position an element would have had in the normal flow. More
precisely:
</p>
<ul>
<li>The <dfn>static-position containing block</dfn> is the containing
block of a hypothetical box that would have been the first box of the
element if its specified <a href="visuren.html#propdef-position" class="noxref"><span
class="propinst-position">'position'</span></a> value had been 'static'
and its specified 'float' had been 'none'. (Note that due to the rules
in <a href="visuren.html#dis-pos-flo">section&nbsp;9.7</a> this
hypothetical calculation might require also assuming a different
computed value for 'display'.)
</li>
<li>The static position for 'left' is the distance from the left edge
of the containing block to the left margin edge of a hypothetical box
that would have been the first box of the element if its <a href="visuren.html#propdef-position" class="noxref"><span
class="propinst-position">'position'</span></a> property had been 'static'
and <a href="visuren.html#propdef-float" class="noxref"><span class="propinst-float">'float'</span></a> had been 'none'. The
value is negative if the hypothetical
box is to the left of the containing block.
</li>
<li>The static position for 'right' is the distance from the right
edge of the containing block to the right margin edge of the same
hypothetical box as above. The value is positive if the hypothetical
box is to the left of the containing block's edge.
</li>
</ul>
<p>But rather than actually calculating the dimensions of that
hypothetical box, user agents are free to make a guess at its probable
position.
</p>
<p>For the purposes of calculating the static position, the containing
block of fixed positioned elements is the initial containing block
instead of the viewport, and all scrollable boxes should be assumed to
be scrolled to their origin.
<p>The constraint that determines the used values for these
elements is:</p>
<blockquote>
<p>'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width'
+ 'padding-right' + 'border-right-width' + 'margin-right' + 'right' = width
of containing block </p>
</blockquote>
<p>If all three of 'left', 'width', and 'right' are 'auto': First set
any 'auto' values for 'margin-left' and 'margin-right' to 0. Then, if
the 'direction' property of the element establishing the
static-position containing block is 'ltr' set 'left'
to the <a
href="#static-position">static position</a> and apply rule number
three below; otherwise, set 'right' to the <a
href="#static-position">static position</a> and apply rule number
one below.</p>
<p>If none of the three is 'auto': If both 'margin-left' and
'margin-right' are 'auto', solve the
equation under the extra constraint that the two margins get equal
values, unless this would make them negative, in which case when
direction of the containing block is 'ltr' ('rtl'), set 'margin-left'
('margin-right') to zero
and solve for 'margin-right' ('margin-left'). If one of
'margin-left' or 'margin-right' is 'auto', solve the equation for that
value. If the values are over-constrained, ignore the value for 'left'
(in case the 'direction' property of the containing block is 'rtl') or
'right' (in case 'direction' is
'ltr') and solve for that value.</p>
<p>Otherwise, set 'auto' values for 'margin-left' and 'margin-right'
to 0, and pick the one of the following six rules that applies.</p>
<ol>
<li>'left' and 'width' are 'auto' and 'right' is not 'auto', then the
width is shrink-to-fit. Then solve for 'left'</li>
<li>'left' and 'right' are 'auto' and 'width' is not 'auto', then if
the 'direction' property of the element establishing the
static-position containing block is 'ltr' set 'left'
to the <a
href="#static-position">static position</a>, otherwise set 'right'
to the <a href="#static-position">static position</a>. Then solve
for 'left' (if 'direction is 'rtl') or 'right' (if 'direction' is
'ltr').</li>
<li>'width' and 'right' are 'auto' and 'left' is not 'auto', then the
width is shrink-to-fit . Then solve for 'right'</li>
<li>'left' is 'auto', 'width' and 'right' are not 'auto', then solve for
'left'</li>
<li>'width' is 'auto', 'left' and 'right' are not 'auto', then solve
for 'width'</li>
<li>'right' is 'auto', 'left' and 'width' are not 'auto', then solve
for 'right'</li>
</ol>
<p>Calculation of the shrink-to-fit width is similar to calculating
the width of a table cell using the automatic table layout algorithm.
Roughly: calculate the preferred width by formatting the content
without breaking lines other than where explicit line breaks occur,
and also calculate the preferred <em>minimum</em> width, e.g., by
trying all possible line breaks. CSS&nbsp;2.1 does not define the
exact algorithm. Thirdly, calculate the <em>available width</em>: this
is found by solving for 'width' after setting 'left' (in case 1) or
'right' (in case 3) to 0.</p>
<p>Then the shrink-to-fit width is: min(max(preferred minimum width, available
width), preferred width).</p>
<h3>10.3.8 <a name="abs-replaced-width">Absolutely positioned, replaced elements</a></h3>
<p>In this case, <a href="#abs-non-replaced-width">section 10.3.7</a>
applies up through and including the constraint equation, but the rest
of <a href="#abs-non-replaced-width">section 10.3.7</a> is replaced by
the following rules:
<ol>
<li>The used value of <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> is
determined as for <a href="#inline-replaced-width">inline replaced
elements</a>.
If <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> is specified as
'auto' its used value is determined by the rules below.
</li>
<li>If both <a href="visuren.html#propdef-left" class="noxref"><span class="propinst-left">'left'</s 5E37 pan></a> and <a href="visuren.html#propdef-right" class="noxref"><span
class="propinst-right">'right'</span></a> have the value 'auto', then if
the 'direction' property of the element establishing the
static-position containing block is 'ltr', set <a href="visuren.html#propdef-left" class="noxref"><span
class="propinst-left">'left'</span></a> to
the static position; else if 'direction' is 'rtl', set <a href="visuren.html#propdef-right" class="noxref"><span
class="propinst-right">'right'</span></a> to the static position.
</li>
<li>If <a href="visuren.html#propdef-left" class="noxref"><span class="propinst-left">'left'</span></a> or <a href="visuren.html#propdef-right" class="noxref"><span
class="propinst-right">'right'</span></a> are 'auto', replace any 'auto'
on <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> with '0'.
</li>
<li>If at this point both <a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a> and <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> are still 'auto',
solve the equation under the extra constraint that the two margins
must get equal values, unless this would make them negative, in which
case when the direction of the containing block is 'ltr' ('rtl'), set
<a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a> (<a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a>) to zero and solve
for <a href="box.html#propdef-margin-right" class="noxref"><span class="propinst-margin-right">'margin-right'</span></a> (<a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a>).
</li>
<li>If at this point there is an 'auto' left, solve the equation
for that value.
</li>
<li>If at this point the values are over-constrained, ignore the value
for either <a href="visuren.html#propdef-left" class="noxref"><span class="propinst-left">'left'</span></a> (in case the
<a href="visuren.html#propdef-direction" class="noxref"><span class="propinst-direction">'direction'</span></a> property of the
containing block is 'rtl') or <a href="visuren.html#propdef-right" class="noxref"><span
class="propinst-right">'right'</span></a> (in case <a href="visuren.html#propdef-direction" class="noxref"><span
class="propinst-direction">'direction'</span></a> is 'ltr') and solve for
that value.
</li>
</ol>
<h3>10.3.9 <a name="inlineblock-width">'Inline-block', non-replaced elements in normal flow</a></h3>
<p>If <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> is 'auto', the
used value is the <a href="#shrink-to-fit-float">shrink-to-fit</a>
width as for floating elements.
</p>
<p>A computed value of 'auto' for <a href="box.html#propdef-margin-left" class="noxref"><span
class="propinst-margin-left">'margin-left'</span></a> or <a href="box.html#propdef-margin-right" class="noxref"><span
class="propinst-margin-right">'margin-right'</span></a> becomes a used
value of '0'.
</p>
<h3>10.3.10 <a name="inlineblock-replaced-width">'Inline-block', replaced elements in normal flow</a></h3>
<p>Exactly as <a href="#inline-replaced-width">inline replaced
elements.</a>
</p>
<h2>10.4 <a name="min-max-widths">Minimum and maximum widths</a>: <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a> and <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a></h2>
<div class="propdef">
<dl><dt>
<span class="index-def" title="'min-width'"><a name="propdef-min-width" class="propdef-title"><strong>'min-width'</strong></a></span>
<dd>
<table class="propinfo" cellspacing=0 cellpadding=0>
<tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length">&lt;length&gt;</span></a> | <a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage">&lt;percentage&gt;</span></a> | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a>
<tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>0
<tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements but non-replaced inline elements, table rows, and row groups
<tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no
<tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage as specified or the absolute length
</table>
</dl>
</div>
<div class="propdef">
<dl><dt>
<span class="index-def" title="'max-width'"><a name="propdef-max-width" class="propdef-title"><strong>'max-width'</strong></a></span>
<dd>
<table class="propinfo" cellspacing=0 cellpadding=0>
<tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length">&lt;length&gt;</span></a> | <a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage">&lt;percentage&gt;</span></a> | none | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a>
<tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>none
<tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements but non-replaced inline elements, table rows, and row groups
<tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no
<tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage as specified or the absolute length or 'none'
</table>
</dl>
</div>
<p>These two properties allow authors to constrain content widths to a
certain range. Values have the following meanings:</p>
<dl>
<dt><span class="index-inst" title="&lt;length&gt;"><a name="x8" href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><strong>&lt;length&gt;</strong></span></a></span>
</dt>
<dd>Specifies a fixed minimum or maximum used width.
</dd>
<dt><span class="index-inst" title="&lt;percentage&gt;"><a name="x9" href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span></a></span>
</dt>
<dd>Specifies a percentage for determining the used value. The
percentage is calculated with respect to the width of the generated
box's <a href="visuren.html#containing-block">containing block</a>.
If the containing block's width is negative, the used value is
zero.
If the containing block's width depends on this element's width,
then the resulting layout is undefined in CSS 2.1.
</dd>
<dt><strong>none</strong>
</dt>
<dd>(Only on <a href="visudet.html#propdef-max-width" class="noxref"><span class="propinst-max-width">'max-width'</span></a>) No
limit on the width of the box.
</dd>
</dl>
<p>Negative values for <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a> and <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a> are illegal.
</p>
<p>In CSS&nbsp;2.1, the effect of 'min-width' and 'max-width' on
tables, inline tables,
table cells, table columns, and column groups is undefined.
<p>The following algorithm describes how the two properties influence
the <a href="cascade.html#computed-value">used value</a>
of the <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> property:</p>
<ol>
<li>The tentative used width is calculated (without <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a> and <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a>) following the rules
under <a href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above.
</li>
<li>If the tentative used width is greater than <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a>, the rules <a
href="#Computing_widths_and_margins">above</a> are applied again, but
this time using the computed value of <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a> as the computed value
for <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a>.
</li>
<li>If the resulting width is smaller than <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a>, the rules <a
href="#Computing_widths_and_margins">above</a> are applied again, but
this time using the value of <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a> as the computed value
for <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a>.
</li>
</ol>
<p class="note">These steps do not affect the real computed values of
the above properties.</p>
<p>However, for replaced elements with an intrinsic ratio and both
<a href="visudet.html#propdef-width" class="noxref"><span
class="propinst-width">'width'</span></a> and <a href="visudet.html#propdef-height" class="noxref"><span
class="propinst-height">'height'</span></a> specified as 'auto', the
algorithm is as follows:
</p>
<p>Select from the table the resolved height and width values for the
appropriate constraint violation. Take the <var>max-width</var> and
<var>max-height</var> as max(min, max) so that <var>min</var> &#8804;
<var>max</var> holds true.
In this table <var>w</var> and <var>h</var> stand for the results of
the width and height computations ignoring the <a href="visudet.html#propdef-min-width" class="noxref"><span
class="propinst-min-width">'min-width'</span></a>, <a href="visudet.html#propdef-min-height" class="noxref"><span
class="propinst-min-height">'min-height'</span></a>, <a href="visudet.html#propdef-max-width" class="noxref"><span
class="propinst-max-width">'max-width'</span></a> and <a href="visudet.html#propdef-max-height" class="noxref"><span
class="propinst-max-height">'max-height'</span></a> properties. Normally
these are the intrinsic width and height, but they may not be in the
case of replaced elements with intrinsic ratios.
<p class=note>Note: In cases where an explicit width or height is
set and the other dimension is auto, applying a minimum or maximum
constraint on the auto side can cause an over-constrained situation.
The spec is clear in the behavior but it might not be what the author
expects. The CSS3 object-fit property can be used to obtain different
results in this situation.
<table rules=all>
<thead>
<tr><th>Constraint Violation</th><th>Resolved Width</th><th>Resolved Height</th></tr>
</thead>
<tbody>
<tr><td>none</td>
<td><var>w</var></td>
<td><var>h</var></td></tr>
<tr><td><var>w&nbsp;>&nbsp;max-width</var></td>
<td><var>max-width</var></td>
<td><var>max(max-width&nbsp;*&nbsp;h/w, min-height)</var></td></tr>
<tr><td><var>w&nbsp;&lt;&nbsp;min-width</var></td>
<td><var>min-width</var></td>
<td><var>min(min-width&nbsp;*&nbsp;h/w, max-height)</var></td></tr>
<tr><td><var>h&nbsp;>&nbsp;max-height</var></td>
<td><var>max(max-height&nbsp;*&nbsp;w/h, min-width)</var></td>
<td><var>max-height</var></td></tr>
<tr><td><var>h&nbsp;&lt;&nbsp;min-height</var></td>
<td><var>min(min-height&nbsp;*&nbsp;w/h, max-width)</var></td>
<td><var>min-height</var></td></tr>
<tr><td>(<var>w&nbsp;>&nbsp;max-width</var>) and (<var>h&nbsp;>&nbsp;max-height</var>), where (<var>max-width/w&nbsp;&#8804;&nbsp;max-height/h</var>)</td>
<td><var>max-width</var></td>
<td><var>max(min-height, max-width&nbsp;*&nbsp;h/w)</var></td></tr>
<tr><td>(<var>w&nbsp;>&nbsp;max-width</var>) and (<var>h&nbsp;>&nbsp;max-height</var>), where (<var>max-width/w&nbsp;>&nbsp;max-height/h</var>)</td>
<td><var>max(min-width, max-height&nbsp;*&nbsp;w/h)</var></td>
<td><var>max-height</var></td></tr>
<tr><td>(<var>w&nbsp;&lt;&nbsp;min-width</var>) and (<var>h&nbsp;&lt;&nbsp;min-height</var>), where (<var>min-width/w&nbsp;&#8804;&nbsp;min-height/h</var>)</td>
<td><var>min(max-width, min-height&nbsp;*&nbsp;w/h)</var></td>
<td><var>min-height</var></td></tr>
<tr><td>(<var>w&nbsp;&lt;&nbsp;min-width</var>) and (<var>h&nbsp;&lt;&nbsp;min-height</var>), where (<var>min-width/w&nbsp;>&nbsp;min-height/h</var>)</td>
<td><var>min-width</var></td>
<td><var>min(max-height, min-width&nbsp;*&nbsp;h/w)</var></td></tr>
<tr><td>(<var>w&nbsp;&lt;&nbsp;min-width</var>) and (<var>h&nbsp;>&nbsp;max-height</var>)</td>
<td><var>min-width</var></td>
<td><var>max-height</var></td></tr>
<tr><td>(<var>w&nbsp;>&nbsp;max-width</var>) and (<var>h&nbsp;&lt;&nbsp;min-height</var>)</td>
<td><var>max-width</var></td>
<td><var>min-height</var></td></tr>
</tbody>
</table>
<p>Then apply the rules under <a
href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above, as if <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a>
were computed as this value.
<h2>10.5 <a name="the-height-property">Content height</a>: the <a href="visudet.html#propdef-height" class="noxref"><span
class="propinst-height">'height'</span></a> property</h2>
<div class="propdef">
<dl><dt>
<span class="index-def" title="'height'"><a name="propdef-height" class="propdef-title"><strong>'height'</strong></a></span>
<dd>
<table class="propinfo" cellspacing=0 cellpadding=0>
<tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length">&lt;length&gt;</span></a> | <a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage">&lt;percentage&gt;</span></a> | auto | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a>
<tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>auto
<tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements but non-replaced inline elements, table columns, and column groups
<tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no
<tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>see prose
<tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage or 'auto' (as specified) or the absolute length
</table>
</dl>
</div>
<p> This property specifies the <a
href="box.html#content-height">content height</a> of boxes.
<p>This property does not apply to non-replaced <a
href="visuren.html#inline-boxes">inline</a> elements. See the <a
href="#inline-non-replaced">section on computing heights and margins
for non-replaced inline elements</a> for the rules used instead.
</p>
<p>Values have the following meanings:</p>
<dl>
<dt><span class="index-inst" title="&lt;length&gt;"><a name="x11" href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><strong>&lt;length&gt;</strong></span></a></span>
</dt>
<dd>Specifies the height of the content area using a length value.
</dd>
<dt><span class="index-inst" title="&lt;percentage&gt;"><a name="x12" href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span></a></span>
</dt>
<dd>Specifies a percentage height. The percentage is calculated with
respect to the height of the generated box's <a
href="visuren.html#containing-block">containing block</a>. If the
height of the containing block is not specified explicitly (i.e., it
depends on content height), and this element is not absolutely
positioned, the used height is calculated as if 'auto' was specified.
A percentage height
on the <a href="conform.html#root">root element</a> is relative to the
<a href="#containing-block-details">initial containing block</a>.
<span class="note">
Note: For absolutely positioned elements whose containing block is
based on a block-level element, the percentage is calculated with
respect to the height of the <em>padding box</em> of that element.
This is a change from CSS1, where the percentage was always
calculated with respect to the <em>content box</em> of the parent
element.
</span>
</dd>
<dt><strong>auto</strong>
</dt>
<dd>The height depends on the values of other properties.
See the prose below.
</dd>
</dl>
<p class="note">Note that the height of the containing block of an
absolutely positioned element is independent of the size of the
element itself, and thus a percentage height on such an element can
always be resolved. However, it may be that the height is not known
until elements that come later in the document have been processed.
</p>
<p>Negative values for <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a>
are illegal.
</p>
<div class="example"><P style="display:none">Example(s):</P><p>
For example, the following rule sets the content height of paragraphs
to 100 pixels:</p>
<pre>
p { height: 100px }
</pre>
<p>Paragraphs of which the height of the contents exceeds 100 pixels
will <a href="visufx.html#overflow">overflow</a> according to the
<a href="visufx.html#propdef-overflow" class="noxref"><span class="propinst-overflow">'overflow'</span></a> property.
</p>
</div>
<h2>10.6 <a name="Computing_heights_and_margins">Calculating heights and
margins</a></h2>
<p>For calculating the values of <a href="visuren.html#propdef-top" class="noxref"><span class="propinst-top">'top'</span></a>, <a href="box.html#propdef-margin-top" class="noxref"><span class="propinst-margin-top">'margin-top'</span></a>, <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a>,
<a href="box.html#propdef-margin-bottom" class="noxref"><span class="propinst-margin-bottom">'margin-bottom'</span></a>, and <a href="visuren.html#propdef-bottom" class="noxref"><span class="propinst-bottom">'bottom'</span></a> a distinction must be made between
various kinds of boxes:
</p>
<ol>
<li>inline, non-replaced elements</li>
<li>inline, replaced elements</li>
<li>block-level, non-replaced elements in normal flow</li>
<li>block-level, replaced elements in normal flow</li>
<li>floating, non-replaced elements</li>
<li>floating, replaced elements</li>
<li>absolutely positioned, non-replaced elements</li>
<li>absolutely positioned, replaced elements</li>
<li>'inline-block', non-replaced elements in normal flow</li>
<li>'inline-block', replaced elements in normal flow</li>
</ol>
<p>For Points 1-6 and 9-10, the used values of 'top' and
'bottom' are determined by the rules in section 9.4.3.
</p>
<p class=note>Note: these rules apply to
the root element just as to any other element.
<p class=note><em><strong>Note.</strong> The used value of 'height'
calculated below is a tentative value, and may have to be calculated
multiple times, depending on <a href="visudet.html#propdef-min-height" class="noxref"><span
class="propinst-min-height">'min-height'</span></a> and <a href="visudet.html#propdef-max-height" class="noxref"><span
class="propinst-max-height">'max-height'</span></a>, see the section <a
href="#min-max-heights">Minimum and maximum heights</a> below.</em>
<h3>10.6.1 <a name="inline-non-replaced">Inline, non-replaced elements</a></h3>
<p>The <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> property does not
apply. The height of the content area should be based on the font, but
this specification does not specify how. A UA may, e.g., use the
em-box or the maximum ascender and descender of the font. (The latter
would ensure that glyphs with parts above or below the em-box still
fall within the content area, but leads to differently sized boxes for
different fonts; the former would ensure authors can control
background styling relative to the 'line-height', but leads to glyphs
painting outside their content area.)
</p>
<p class=note>Note: level 3 of CSS will probably include a property to
select which measure of the font is used for the content height.
</p>
<p>The vertical padding, border and margin of an inline, non-replaced
box start at the top and bottom of the content area, and has nothing
to do with the <a href="visudet.html#propdef-line-height" class="noxref"><span
class="propinst-line-height">'line-height'</span></a>. But only the <a href="visudet.html#propdef-line-height" class="noxref"><span