8000 csswg-drafts/css-position/Overview.html at fac66c629e58a242fc6aa900071a71ac65b15977 · xfq/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
executable file
·
4807 lines (3803 loc) · 186 KB

File metadata and controls

executable file
·
4807 lines (3803 loc) · 186 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang=en>
<head
profile="http://dublincore.org/documents/2008/08/04/dc-html/ http://www.w3.org/2006/03/hcard">
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Positioned Layout Module Level 3</title>
<link href="http://purl.org/dc/terms/" rel=schema.dcterms>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dcterms.rights>
<meta content="CSS Positioned Layout Module Level 3" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2014-01-04 name=dcterms.date>
<meta content="Rossen Atanassov" name=dcterms.creator>
<meta content="Arron Eicholz" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/css3-positioning/"
name=dcterms.identifier>
<link href=default.css rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<style type="text/css">
.cb-example-table
{
border: 1px solid;
border-collapse: collapse;
font-size: smaller;
text-align: center;
margin: 0 2em;
}
.cb-example-table td, .cb-example-table th
{
border: 1px solid;
padding: 0 3px;
}
code span, td span
{
white-space: nowrap;
}
.relationship-table
{
border: 1px solid;
border-collapse: collapse;
font-size: smaller;
margin: 0 6em;
}
.relationship-table th
{
text-align: center;
white-space:nowrap;
}
.relationship-table td, .relationship-table th
{
border: 1px solid;
padding: 0 3px;
}
h2 dfn, h3 dfn
{
font: inherit;
}
table.lpr
{
border-collapse: collapse;
}
.lpr td, .lpr th
{
border: 1px solid;
text-align: center;
}
.lpr col
{
background: rgb(221, 238, 255);
border-right: 2px solid;
font-weight: bold;
padding: 0 5px;
}
.lpr div
{
font-weight: bold;
-moz-transform: rotate(-90deg) translatex(-0.5em);
-ms-transform: rotate(-90deg) translatex(-0.5em);
-o-transform: rotate(-90deg) translatex(-0.5em);
-webkit-transform: rotate(-90deg) translatex(-0.5em);
transform: rotate(-90deg) translatex(-0.5em);
width: 1.5em;
}
.lpr th:first-child
{
border: none;
background: white;
}
.lpr tbody td:first-child
{
font-weight: normal;
}
.lpr thead td
{
background: rgb(238, 238, 238);
font-weight: bold;
padding: 0 5px;
vertical-align: bottom;
white-space: nowrap;
}
.lpr thead tr:nth-child(2)
{
border-bottom: 2px solid;
}
</style>
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Positioned Layout Module Level 3</h1>
<h2 class="no-num no-toc">Editor's Draft 4 January 2014</h2>
<dl>
<dt>This version:
<dd><a
href="http://dev.w3.org/csswg/css3-positioning/">http://dev.w3.org/csswg/css3-positioning/</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-positioning/">http://www.w3.org/TR/css3-positioning/</a>
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css3-positioning/">http://dev.w3.org/csswg/css3-positioning/</a>
<dt>Previous version:
<dd><a
href="http://www.w3.org/TR/2012/WD-css3-positioning-20120207/">http://www.w3.org/TR/2012/WD-css3-positioning-20120207/</a>
<dt>Issues List
<dd><a
href="http://wiki.csswg.org/spec/css3-positioning/">http://wiki.csswg.org/spec/css3-positioning/</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss-position%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css-position] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd class=vcard><span class=fn>Rossen Atanassov</span>, <span
class=org>Microsoft Corporation</span>
<dd class=vcard><span class=fn>Arron Eicholz</span>, <span
class=org>Microsoft Corporation</span>
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2014 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p> CSS is a language for describing the rendering of structured documents
(such as HTML and XML) on screen, on paper, in speech, etc. This module
contains the features of CSS level 3 relating to positioning and stacking
of elements. It includes and extends the functionality of CSS level 2 <a
href="#ref-CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, which
builds on CSS level 1 <a href="#ref-CSS1"
rel=biblioentry>[CSS1]<!--{{CSS1}}--></a>. The main extensions compared to
level 2 are the ability to position elements based on CSS Region boxes,
and the ability to specify a different containing blocks for elements.
<p> Other kinds of layout, such as tables, "floating" boxes, ruby
annotations, grid layouts, columns and basic handling of normal "flow"
content, are described in other modules. Also, the layout of text inside
each line is defined elsewhere.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-positioning%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-positioning” in the subject, preferably like this:
“[<!---->css3-positioning<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<!--<p>The following features are at risk:</p>-->
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span>Introduction</a>
<ul class=toc>
<li><a href="#placement"><span class=secno>1.1. </span>Module
Interactions</a>
<li><a href="#values"><span class=secno>1.2. </span>Values</a>
</ul>
<li><a href="#viewport"><span class=secno>2. </span>The Viewport</a>
<li><a href="#containing-block"><span class=secno>3. </span>Containing
Blocks</a>
<ul class=toc>
<li><a href="#def-containing-blocks"><span class=secno>3.1.
</span>Definition of containing block</a>
</ul>
<li><a href="#normal-flow"><span class=secno>4. </span>Normal Flow</a>
<li><a href="#floats"><span class=secno>5. </span>Floats</a>
<li><a href="#positioning-schemes"><span class=secno>6. </span>Positioning
schemes</a>
<ul class=toc>
<li><a href="#relative-positioning"><span class=secno>6.1.
</span>Relative positioning</a>
<li><a href="#sticky-positioning"><span class=secno>6.2. </span><span
class=index-def id=sticky-positioning0
title="sticky positioning|sticky position|stickily positioned">Sticky
positioning</span></a>
<li><a href="#absolute-positioning"><span class=secno>6.3. </span><span
class=index-def id=absolute-positioning0
title="absolute positioning|absolute position|absolutely positioned">Absolute
positioning</span></a>
<li><a href="#center-positioning"><span class=secno>6.4. </span><span
class=index-def id=center-positioning0
title="center positioning|center position|center positioned">Center
positioning</span></a>
<li><a href="#page-positioning"><span class=secno>6.5. </span><span
class=index-def id=page-positioning0
title="page positioning|page position|page positioned">Page
positioning</span></a>
<li><a href="#fixed-positioning"><span class=secno>6.6. </span><span
class=index-def id=fixed-positioning0
title="fixed positioning|fixed position|fixed positioned">Fixed
positioning</span></a>
<li><a href="#position-property"><span class=secno>6.7. </span>Choosing
a positioning scheme: ‘<code class=property>position</code>’
property</a>
<li><a href="#box-offsets-trbl"><span class=secno>6.8. </span>Box
offsets: ‘<code class=property>top</code>’, ‘<code
class=property>right</code>’, ‘<code
class=property>bottom</code>’, ‘<code
c 5D59 lass=property>left</code>’</a>
<li><a href="#logical-box-offsets-beaso"><span class=secno>6.9.
</span>Logical box offsets: ‘<code
class=property>offset-before</code>’, ‘<code
class=property>offset-end</code>’, ‘<code
class=property>offset-after</code>’, ‘<code
class=property>offset-start</code>’, and ‘<code
class=property>offset</code>’</a>
</ul>
<li><a href="#position-root"><span class=secno>7. </span>Choosing a
different containing block for positioning</a>
<ul class=toc>
<li><a href="#attachment-properties"><span class=secno>7.1.
</span>Attachment properties: ‘<code
class=property>attachment-type</code>’, ‘<code
class=property>attachment-top</code>’, ‘<code
class=property>attachment-right</code>’, ‘<code
class=property>attachment-bottom</code>’, ‘<code
class=property>attachment-left</code>’, and ‘<code
class=property>attachment</code>’</a>
</ul>
<li><a href="#size-and-position-details"><span class=secno>8.
</span>Sizing and positioning details</a>
<ul class=toc>
<li><a href="#abs-non-replaced-width"><span class=secno>8.1. </span>The
width of absolute, page or fixed positioned, non-replaced elements</a>
<li><a href="#center-non-replaced-width"><span class=secno>8.2.
</span>The width of a center positioned, non-replaced elements</a>
<li><a href="#abs-replaced-width"><span class=secno>8.3. </span>The
width of absolute, page or fixed positioned, replaced elements</a>
<li><a href="#center-replaced-width"><span class=secno>8.4. </span>The
width of a center positioned, replaced elements</a>
<li><a href="#abs-non-replaced-height"><span class=secno>8.5. </span>The
height of absolute, page or fixed positioned, non-replaced elements</a>
<li><a href="#center-non-replaced-height"><span class=secno>8.6.
</span>The height of a center positioned, non-replaced elements</a>
<li><a href="#abs-replaced-height"><span class=secno>8.7. </span>The
height of absolute, page or fixed positioned, replaced elements</a>
<li><a href="#center-replaced-height"><span class=secno>8.8. </span>The
height of a center positioned, replaced elements</a>
<li><a href="#root-height"><span class=secno>8.9. </span>‘<code
class=property>Auto</code>’ heights for block formatting context
roots</a>
</ul>
<li><a href="#dis-pos-flo"><span class=secno>9. </span>Relationships
between ‘<code class=property>display</code>’, ‘<code
class=property>position</code>’, and ‘<code
class=property>float</code>’</a>
<li><a href="#comparison"><span class=secno>10. </span>Comparison of
normal flow, floats, and positioning</a>
<ul class=toc>
<li><a href="#comp-normal-flow"><span class=secno>10.1. </span>Normal
flow</a>
<li><a href="#comp-relpos"><span class=secno>10.2. </span>Relative
positioning</a>
<li><a href="#comp-floating"><span class=secno>10.3. </span>Floating a
box</a>
<li><a href="#comp-abspos"><span class=secno>10.4. </span>Absolute
positioning</a>
<li><a href="#comp-pagepos"><span class=secno>10.5. </span>Page
positioning</a>
</ul>
<li><a href="#layered-presentation"><span class=secno>11. </span>Layered
presentation</a>
<li><a href="#det-stacking-context"><span class=secno>12. </span>Detailed
stacking context</a>
<ul class=toc>
<li><a href="#definitions-stack"><span class=secno>12.1.
</span>Definitions</a>
<li><a href="#painting-order"><span class=secno>12.2. </span>Painting
order</a>
<li><a href="#stacking-notes"><span class=secno>12.3. </span>Notes</a>
</ul>
<li><a href="#conformance"><span class=secno>13. </span>Conformance</a>
<ul class=toc>
<li><a href="#conventions"><span class=secno>13.1. </span>Document
Conventions</a>
<li><a href="#conformance-classes"><span class=secno>13.2.
</span>Conformance Classes</a>
<li><a href="#partial"><span class=secno>13.3. </span>Partial
Implementations</a>
<li><a href="#experimental"><span class=secno>13.4. </span>Experimental
Implementations</a>
<li><a href="#testing"><span class=secno>13.5. </span>Non-Experimental
Implementations</a>
<li><a href="#cr-exit-criteria"><span class=secno>13.6. </span>CR Exit
Criteria</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span>Introduction</h2>
<p><em>This section is not normative.</em>
<p> CSS assumes the document layout is modeled as a tree of elements. The
unique element that has no parent is called the root element. This module
describes how any of the elements from the tree of elements can be
arranged independent of document order (i.e. taken out of "flow"). With a
positioned element the element may be placed anywhere within the content
not specifically respecting the tree of elements order.
<p> In <a href="#ref-CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>,
the visual formatting model explained how each element in the document
tree generates zero or more boxes according to the box model. This module
further explains and extends the positioning scheme. The layout of these
boxes is governed by:
<ul>
<li><a href="http://www.w3.org/TR/CSS2/box.html#box-dimensions">box
dimensions</a> and <a
href="http://www.w3.org/TR/CSS2/visuren.html#box-gen">type</a>.
<li>positioning scheme (<a href="#normal-flow0">normal flow</a>, float,
and absolute positioning).
<li>relationships between elements in the <a
href="http://www.w3.org/TR/CSS2/conform.html#doctree">document tree</a>.
<li>external information (e.g., viewport size, intrinsic dimensions of
images, etc.).
</ul>
<p>The properties defined in this module apply to both continuous media and
paged media.
<h3 id=placement><span class=secno>1.1. </span>Module Interactions</h3>
<p>This module replaced and extends the positioning scheme features defined
in <a href="#ref-CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
sections:
<ul>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#viewport">9.1.1 The
viewport</a>
<li><a
href="http://www.w3.org/TR/CSS2/visuren.html#containing-block">9.1.2
Containing blocks</a>
<li><a
href="http://www.w3.org/TR/CSS2/visuren.html#positioning-scheme">9.3
Positioning schemes</a>
<li><a
href="http://www.w3.org/TR/CSS2/visuren.html#relative-positioning">9.4.3
Relative positioning</a>
<li><a
href="http://www.w3.org/TR/CSS2/visuren.html#absolute-positioning">9.6
Absolute positioning</a>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">9.7
Relationships between ‘<code class=property>display</code>’, ‘<code
class=property>position</code>’, and ‘<code
class=property>float</code>’</a>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#comparison">9.8
Comparison of normal flow, floats, and absolute positioning</a>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#layers">9.9 Layered
presentation</a>
<li><a
href="http://www.w3.org/TR/CSS2/visudet.html#containing-block-details">10.1
Definition of "containing block"</a>
<li><a
href="http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width">10.3.7
Absolutely positioned, non-replaced elements</a>
<li><a
href="http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-width">10.3.8
Absolutely positioned, replaced elements</a>
<li><a
href="http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-height">10.6.4
Absolutely positioned, non-replaced elements</a>
<li><a
href="http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-height">10.6.5
Absolutely positioned replaced elements</a>
<li><a href="http://www.w3.org/TR/CSS2/visudet.html#root-height">10.6.7
‘<code class=css>Auto</code>’ heights for block formatting context
roots</a>
<li><a href="http://www.w3.org/TR/CSS2/zindex.html">Appendix E. Elaborate
description of Stacking Contexts</a>
</ul>
<!-- End section" Module Interactions -->
<h3 id=values><span class=secno>1.2. </span>Values</h3>
<p>This specification follows the CSS property definition conventions from
<a href="#ref-CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<p> Value types not defined in this specification are defined in CSS Level
2 Revision 1 <a href="#ref-CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Other CSS modules may expand
the definitions of these value types: for example <a href="#ref-CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>, when combined with this
module, expands the definition of the &lt;length&gt; value type as used in
this specification.
<p> In addition to the property-specific values listed in their
definitions, all properties defined in this specification also accept the
<a
href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
keyword as their property value. For readability it has not been repeated
explicitly.</p>
<!-- End section: Values -->
<!-- End section Introduction -->
<h2 id=viewport><span class=secno>2. </span>The <dfn id=viewport0
title=viewport>Viewport</dfn></h2>
<p> User agents for <a
href="http://www.w3.org/TR/CSS2/media.html#continuous-media-group">continuous
media</a> generally offer users a viewport (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
<span>initial containing block</span>).
<p> When the viewport is smaller than the area of the canvas on which the
document is rendered, the user agent may offer a scrolling mechanism.
There is at most one viewport per <a
href="http://www.w3.org/TR/CSS2/intro.html#canvas">canvas</a>, but user
agents may render to more than one canvas (i.e., provide different views
of the same document).</p>
<!-- End section: The Viewport -->
<h2 id=containing-block><span class=secno>3. </span>Containing Blocks</h2>
<p> In CSS, many box positions and sizes are calculated with respect to the
edges of a rectangular box called a containing block. In general,
generated boxes act as containing blocks for descendant boxes; we say that
a box "establishes" the containing block for its descendants. The phrase
"a box's containing block" means "the containing block in which the box
lives," not the one it generates.
<p> Each box is given a position with respect to its containing block, but
it is not confined by this containing block; it may <a
href="http://www.w3.org/TR/CSS2/visufx.html#overflow">overflow</a>.
<h3 id=def-containing-blocks><span class=secno>3.1. </span>Definition of
<dfn id=containing-block0>containing block</dfn></h3>
<p> The position and size of an element's box(es) are sometimes computed
relative to a certain rectangle, called the containing block of the
element. The containing block of a <a href="#static"
title="'position'!!''static''">‘<code class=css>static</code>’</a> or
<a href="#relative" title="'position'!!''relative''">‘<code
class=css>relative</code>’</a> element is defined in the Box Model <a
href="#ref-CSS3BOX" rel=biblioentry>[CSS3BOX]<!--{{!CSS3BOX}}--></a>. The
containing block of a <a href="#sticky"
title="'position'!!'sticky'">‘<code class=property>sticky</code>’</a>
element is the same as for a <a href="#relative"
title="'position'!!''relative''">‘<code class=css>relative</code>’</a>
element. For <a href="#fixed" title="'position'!!''fixed''">‘<code
class=css>fixed</code>’</a>, <a href="#absolute"
title="'position'!!''absolute''">‘<code
class=css>absolute</code>’</a>, <a href="#center"
title="'position'!!''center''">‘<code class=css>center</code>’</a> and
<a href="#page" title="'position'!!''page''">‘<code
class=css>page</code>’</a>, it is defined as follows:
<ol>
<li> If the element has <a href="#fixed"
title="'position'!!''fixed''">‘<code class=css>positioned:
fixed</code>’</a>, the containing block is established by the <a
href="#viewport0">viewport</a> in the case of continuous media or the
page area in the case of paged media.
<li> If the element has <a href="#absolute"
title="'position'!!''absolute''">‘<code class=css>position:
absolute</code>’</a>, the containing block is established by the
nearest ancestor with a ‘<a href="#position"><code
class=property>position</code></a>’ other than <a href="#static"
title="'position'!!''static''">‘<code class=css>static</code>’</a>,
in the following way:
<ol>
<li> In the case that the ancestor is block-level, the containing block
is formed by the padding edge of the ancestor.
<li> In the case that the ancestor is inline-level, the containing block
depends on the ‘<code class=property>direction</code>’ property of
the ancestor:
<ol>
<li> If the ‘<code class=property>direction</code>’ is ‘<code
class=css>ltr</code>’, the top and left of the containing block are
the top and left content edges of the first box generated by the
ancestor, and the bottom and right are the bottom and right content
edges of the last box of the ancestor.
<li> If the ‘<code class=property>direction</code>’ is ‘<code
class=css>rtl</code>’, the top and right are the top and right
edges of the first box generated by the ancestor, and the bottom and
left are the bottom and left content edges of the last box of the
ancestor.
<p class=note> Note, in some cases when a line wraps it may seem as
if the left and right positions are swapped.
</ol>
</ol>
<li> I the element has <a href="#center"
title="'position'!!''center''">‘<code class=css>position:
center</code>’</a>, the containing block is established by the nearest
ancestor with a ‘<a href="#position"><code
class=property>position</code></a>’ other than <a href="#static"
title="'position'!!''static''">‘<code class=css>static</code>’</a>,
in the following way:
<ol>
<li> In the case that the ancestor is block-level, the containing block
is formed by the padding edge of the ancestor.
<li> In the case that the ancestor is inline-level, the containing block
depends on the content edges of the boxes generated by the ancestor.
The top most, right most, bottom most and left most content edges of
all the boxes generated by the ancestor determine the edges for the
containing block.
</ol>
<li> If the element has <a href="#page"
title="'position'!!''page''">‘<code class=css>position:
page</code>’</a> and the element is within paged media or within a
rerion, the containing block is the <span>initial containing
block</span>. This is the <a href="#viewport0">viewport</a> or the page
area when in paged media. In the case of CSS Regions <a
href="#ref-CSS3-REGIONS"
rel=biblioentry>[CSS3-REGIONS]<!--{{!CSS3-REGIONS}}--></a> this is the
individual region. When a page positioned element is not in paged media
or a region the containing block is determined per the absolute
positioning model.
<li>If there is no such ancestor, the containing block is the
<span>initial containing block</span>.
</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> 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 the current page,
<li>on a subsequent page, or
<li>may omit it altogether.
</ul>
<p class=note> Note, 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.
<div class=example>
<p>With no positioning, the containing blocks (C.B.) in the following
document:
<pre><code class=html>
&lt;!DOCTYPE html&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;
</code></pre>
<p>are established as follows:
<table class=cb-example-table>
<tbody>
<tr>
<th>For box generated by
<th>C.B. is established by
<tr>
<td>html
<td>initial C.B. (UA-dependent)
<tr>
<td>body
<td>html
<tr>
<td>div1
<td>body
<tr>
<td>p1
<td>div1
<tr>
<td>p2
<td>div1
<tr>
<td>em1
<td>p2
<tr>
<td>strong1
<td>p2
</table>
<p>If we position "div1":
<pre><code class=css>
#div1 { position: absolute; left: 50px; top: 50px }
</code></pre>
<p> its containing block is no longer "body"; it becomes the <span>initial
containing block</span> (since there are no other positioned ancestor
boxes).
<p>If we position "em1" as well:
<pre><code class=css>
#div1 { position: absolute; left: 50px; top: 50px }
#em1 { position: absolute; left: 100px; top: 100px }
</code></pre>
<p>the table of containing blocks becomes:
<table class=cb-example-table>
<tbody>
<tr>
<th>For box generated by
<th>C.B. is established by
<tr>
<td>html
<td>initial C.B. (UA-dependent)
<tr>
<td>body
<td>html
<tr>
<td>div1
<td>initial C.B.
<tr>
<td>p1
<td>div1
<tr>
<td>p2
<td>div1
<tr>
<td>em1
<td>div1
<tr>
<td>strong1
<td>em1
</table>
<p> By positioning "em1", its containing block becomes the nearest
positioned ancestor box (i.e., that generated by "div1").
</div>
<!-- End section: Containing blocks -->
<h2 id=normal-flow><span class=secno>4. </span><dfn id=normal-flow0
title="normal flow">Normal Flow</dfn></h2>
<p> Boxes in the normal flow belong to a formatting context, which may be
block or inline, but not both simultaneously. See the CSS Basic Box Model
module <a href="#ref-CSS3BOX"
rel=biblioentry>[CSS3BOX]<!--{{!CSS3BOX}}--></a> for further details about
<a href="http://www.w3.org/TR/CSS2/visuren.html#normal-flow">normal
flow</a>.</p>
<!-- End section: Normal Flow -->
<h2 id=floats><span class=secno>5. </span><dfn id=floats0
title="float|floated box|floating box">Floats</dfn></h2>
<p> A float is a box that is positioned within content, often left or right
on the current line. The most interesting characteristic of a float (or
"floated" or "floating" box) is that inline-level content may flow along
its side (or be prohibited from doing so by the ‘<code
class=property>clear</code>’ property) or around the floated box. See
the CSS 2.1 <a href="#ref-CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a><!--CSS Floats module [[!CSS3FLOATS]]-->
for details about <a
href="http://www.w3.org/TR/CSS2/visuren.html#floats">floating boxes</a>.</p>
<!-- End section: Floats -->
<h2 id=positioning-schemes><span class=secno>6. </span><dfn
id=positioning-schemes0 title="positioning schemes">Positioning
schemes</dfn></h2>
<p>In CSS, a box may be laid out according to three positioning schemes:
<ol>
<li> Normal flow<br>
In CSS, <a href="#normal-flow0">normal flow</a> includes <a
href="http://www.w3.org/TR/CSS2/visuren.html#block-formatting">block
formatting</a> of block-level boxes, <a
href="http://www.w3.org/TR/CSS2/visuren.html#inline-formatting">inline
formatting</a> of inline-level boxes, and <a
href="#relative-positioning0" title="relative positioning">relative</a>
and <span title="sticky positioning">sticky</span> positioning of
block-level and inline-level boxes.
<li> Floats<br>
In the <a href="#floats0" title=floats>float</a> model, a box is first
laid out according to the <a href="#normal-flow0">normal flow</a>, then
taken out of the flow and positioned, typically to the left or right.
Content may flow along the side of a <a href="#floats0"
title=floats>float</a>.
<li> Absolute positioning<br>
In the absolute positioning model, a box is removed from the <a
href="#normal-flow0">normal flow</a> entirely (it has no impact on later
siblings) and assigned a position with respect to a <a
href="#containing-block0">containing block</a>.
</ol>
<p> An element is called <em>out-of-flow</em> if it is <a href="#floats0"
title=floats>floated</a>, absolutely positioned, or is the root element.
An element is called <em>in-flow</em> if it is not out-of-flow. The
<em>flow of an element</em> A is the set consisting of A and all in-flow
elements whose nearest out-of-flow ancestor is A.
<h3 id=relative-positioning><span class=secno>6.1. </span><dfn
id=relative-positioning0
title="relative positioning|relative position|relatively positioned">Relative
positioning</dfn></h3>
<p> Once a box has been laid out according to the <a
href="#normal-flow0">normal flow</a> or <a href="#floats0"
title=floats>floated</a>, it may be offset relative to this position. This
is called relative positioning. Offsetting a box (B1) in this way has no
effect on the box (B2) that follows: B2 is given a position as if B1 were
not offset and B2 is not re-positioned after B1's offset is applied. This
implies that relative positioning may cause boxes to overlap. However, if
relative positioning causes an ‘<code class=css>overflow: auto</code>’
or ‘<code class=css>overflow: scroll</code>’ box to have overflow, the
user agent must allow the user to access this content (at its offset
position), which, through the creation of a scrolling mechanism, may
affect layout.
<p> A relatively positioned box keeps its <a href="#normal-flow0">normal
flow</a> size, including line breaks and the space originally reserved for
it.
<p> A relatively positioned 8793 box establishes a new a new <a
href="#containing-block0">containing block</a> for absolutely positioned
descendants. (This is a common use of relatively positioned boxes.) The
section on <a href="#containing-block0"
title="containing block">containing blocks</a> explains when a relatively
positioned box establishes a new <a href="#containing-block0">containing
block</a>.
<p> For relatively positioned elements, ‘<a href="#left"><code
class=property>left</code></a>’ and ‘<a href="#right"><code
class=property>right</code></a>’ move the box(es) horizontally, without
changing their size. ‘<a href="#left"><code
class=property>Left</code></a>’ moves the boxes to the right, and ‘<a
href="#right"><code class=property>right</code></a>’ moves them to the
left. Since boxes are not split or stretched as a result of ‘<a
href="#left"><code class=property>left</code></a>’ or ‘<a
href="#right"><code class=property>right</code></a>’, the used values
are always: left = -right.
<p> If both ‘<a href="#left"><code class=property>left</code></a>’ and
‘<a href="#right"><code class=property>right</code></a>’ are ‘<code
class=css>auto</code>’ (their initial values), the used values are
‘<code class=css>0</code>’ (i.e., the boxes stay in their original
position).
<p> If ‘<a href="#left"><code class=property>left</code></a>’ is
‘<code class=css>auto</code>’, its used value is minus the value of
‘<a href="#right"><code class=property>right</code></a>’ (i.e., the
boxes move to the left by the value of ‘<a href="#right"><code
class=property>right</code></a>’).
<p>If ‘<a href="#right"><code class=property>right</code></a>’ is
specified as ‘<code class=css>auto</code>’, its used value is minus
the value of ‘<a href="#left"><code class=property>left</code></a>’.
<p> If neither ‘<a href="#left"><code class=property>left</code></a>’
nor ‘<a href="#right"><code class=property>right</code></a>’ is
‘<code class=css>auto</code>’, the position is over-constrained, and
one of them has to be ignored. If the ‘<code
class=property>direction</code>’ property of the <a
href="#containing-block0">containing block</a> is ‘<code
class=css>ltr</code>’, the value of ‘<a href="#left"><code
class=property>left</code></a>’ wins and ‘<a href="#right"><code
class=property>right</code></a>’ becomes -‘<a href="#left"><code
class=property>left</code></a>’. If ‘<code
class=property>direction</code>’ of the containing block is ‘<code
class=css>rtl</code>’, ‘<a href="#right"><code
class=property>right</code></a>’ wins and ‘<a href="#left"><code
class=property>left</code></a>’ is ignored.
<div class=example>
<p>The following three rules are equivalent:
<pre><code class=css>
div.a8 { position: relative; direction: ltr; left: -1em; right: auto }
div.a8 { position: relative; direction: ltr; left: auto; right: 1em }
div.a8 { position: relative; direction: ltr; left: -1em; right: 5em }
</code></pre>
</div>
<p> The ‘<a href="#top"><code class=property>top</code></a>’ and ‘<a
href="#bottom"><code class=property>bottom</code></a>’ properties move
relatively positioned element(s) up or down without changing their size.
‘<a href="#top"><code class=property>Top</code></a>’ moves the boxes
down, and ‘<a href="#bottom"><code class=property>bottom</code></a>’
moves them up. Since boxes are not split or stretched as a result of ‘<a
href="#top"><code class=property>top</code></a>’ or ‘<a
href="#bottom"><code class=property>bottom</code></a>’, the used values
are always: top = -bottom.
<p>If ‘<a href="#top"><code class=property>top</code></a>’ and ‘<a
href="#bottom"><code class=property>bottom</code></a>’ are ‘<code
class=css>auto</code>’, their used values are both ‘<code
class=css>0</code>’.
<p> If one of them, ‘<a href="#top"><code
class=property>top</code></a>’ or ‘<a href="#bottom"><code
class=property>bottom</code></a>’, is ‘<code class=css>auto</code>’,