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

Latest commit

 

History

History
executable file
·
3201 lines (3143 loc) · 167 KB

File metadata and controls

executable file
·
3201 lines (3143 loc) · 167 KB
<!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head profile="http://www.w3.org/2006/03/hcard">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS Positioned Layout Module Level 3</title>
<link rel="stylesheet" type="text/css" href="default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].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>
</head>
<body>
<div class="head">
<!--logo-->
<h1>CSS Positioned Layout Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:</dt>
<dd><a href="[VERSION]">[VERSION]</a></dd>
<dt>Latest version:</dt>
<dd><a href="http://www.w3.org/TR/[SHORTNAME]/">http://www.w3.org/TR/[SHORTNAME]/</a></dd>
<dt>Editor&#39;s draft:
<dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a></dd>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2012/WD-css3-positioning-20120207/">http://www.w3.org/TR/2012/WD-css3-positioning-20120207/</a></dd>
<dt>Issues List</dt>
<dd><a href="http://wiki.csswg.org/spec/[SHORTNAME]/">http://wiki.csswg.org/spec/[SHORTNAME]/</a></dd>
<dt>Feedback:
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss-position%5D%20feedback">www-style@w3.org</a> with subject line &ldquo;<kbd>[css-position] <var>&hellip; message topic &hellip;</var></kbd>&rdquo; (<a rel="discussion" href="http://lists.w3.org/Archives/Public/www-style/">archives</a>)
<dt>Editors:</dt>
<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>
<!--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&nbsp;3
relating to positioning and stacking of elements. It includes and extends the
functionality of CSS level&nbsp;2 [[!CSS21]], which builds on CSS level&nbsp;1 [[CSS1]].
The main extensions compared to level&nbsp;2 are the ability to position elements based
on CSS Region boxes, and the ability to specify a different containing blocks for elements.
</p>
<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.
</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<!--<p>The following features are at risk:</p>-->
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<h2 id="intro">Introduction</h2>
<p><em>This section is not normative.</em></p>
<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>
<p>
In [[!CSS21]], 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:
</p>
<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>
<li>positioning scheme (<span>normal flow</span>, float, and absolute positioning). </li>
<li>relationships between elements in the <a href="http://www.w3.org/TR/CSS2/conform.html#doctree">document tree</a>.</li>
<li>external information (e.g., viewport size, intrinsic dimensions of images, etc.).</li>
</ul>
<p>The properties defined in this module apply to both continuous media and paged media. </p>
<h3 id="placement">Module Interactions</h3>
<p>This module replaced and extends the positioning scheme features defined in [[!CSS21]] sections:</p>
<ul>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#viewport">9.1.1 The viewport</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#containing-block">9.1.2 Containing blocks</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#positioning-scheme">9.3 Positioning schemes</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#relative-positioning">9.4.3 Relative positioning</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#absolute-positioning">9.6 Absolute positioning</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">9.7 Relationships between 'display', 'position', and 'float'</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#comparison">9.8 Comparison of normal flow, floats, and absolute positioning</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visuren.html#layers">9.9 Layered presentation</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visudet.html#containing-block-details">10.1 Definition of "containing block"</a></li>
<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>
<li><a href="http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-width">10.3.8 Absolutely positioned, replaced elements</a></li>
<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>
<li><a href="http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-height">10.6.5 Absolutely positioned replaced elements</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visudet.html#root-height">10.6.7 ''Auto'' heights for block formatting context roots</a></li>
<li><a href="http://www.w3.org/TR/CSS2/visufx.html#clipping">11.1.2 Clipping: the 'clip' property</a></li>
<li><a href="http://www.w3.org/TR/CSS2/zindex.html">Appendix E. Elaborate description of Stacking Contexts</a></li>
</ul>
<!-- End section" Module Interactions -->
<h3 id="values">Values</h3>
<p>This specification follows the CSS property definition conventions from [[!CSS21]].</p>
<p>
Value types not defined in this specification are defined in CSS Level 2 Revision 1
[[!CSS21]]. Other CSS modules may expand the definitions of these value types: for
example [[!CSS3VAL]], when combined with this module, expands the definition of the &lt;length&gt;
value type as used in this specification.
</p>
<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">The <dfn 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&#39;s layout when the
viewport is resized (see the <span>initial containing block</span>).
</p>
<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">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&#39;s containing block" means "the containing
block in which the box lives," not the one it generates.
</p>
<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>.
</p>
<h3 id="def-containing-blocks">Definition of <dfn>containing block</dfn></h3>
<p>
The position and size of an element&#39;s box(es) are sometimes computed relative to a
certain rectangle, called the containing block of the element. The containing block of a
<span title="'position'!!''static''">''static''</span> or
<span title="'position'!!''relative''">''relative''</span> element is defined in the
Box Model [[!CSS3BOX]]. The containing block of a
<span title="'position'!!'sticky'">'sticky'</span> element is the same as for a
<span title="'position'!!''relative''">''relative''</span> element.
For <span title="'position'!!''fixed''">''fixed''</span>,
<span title="'position'!!''absolute''">''absolute''</span>,
<span title="'position'!!''center''">''center''</span> and
<span title="'position'!!''page''">''page''</span>, it is defined as follows:
</p>
<ol>
<li>
If the element has <span title="'position'!!''fixed''">'positioned: fixed'</span>, the containing block is established by the
<span>viewport</span> in the case of continuous media or the page area in
the case of paged media.
</li>
<li>
If the element has <span title="'position'!!''absolute''">'position: absolute'</span>, the containing block is established
by the nearest ancestor with a 'position' other than <span title="'position'!!''static''">''static''</span>, 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>
<li>
In the case that the ancestor is inline-level, the containing block depends
on the 'direction' property of the ancestor:
<ol>
<li>
If the 'direction' is ''ltr'', 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>
<li>
If the 'direction' is ''rtl'', 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.
</p>
</li>
</ol>
</li>
</ol>
</li>
<li>
I the element has <span title="'position'!!''center''">'position: center'</span>, the containing block is established
by the nearest ancestor with a 'position' other than <span title="'position'!!''static''">''static''</span>, 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>
<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.
</li>
</ol>
</li>
<li>
If the element has <span title="'position'!!''page''">'position: page'</span> and
the element is within paged media or within a rerion, the containing block is the
<span>initial containing block</span>. This is the <span>viewport</span> or the page
area when in paged media. In the case of CSS Regions [[!CSS3-REGIONS]] 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>
<li>If there is no such ancestor, the containing block is the <span>initial containing block</span>.</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:
</p>
<ul>
<li>on the current page,</li>
<li>on a subsequent page, or</li>
<li>may omit it altogether.</li>
</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.
</p>
<div class="example">
<p>With no positioning, the containing blocks (C.B.) in the following document:</p>
<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:</p>
<table class="cb-example-table">
<tr><th>For box generated by </th>
<th>C.B. is established by</th></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><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>
<p>If we position "em1" as well:</p>
<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:</p>
<table class="cb-example-table">
<tr><th>For box generated by</th>
<th>C.B. is established by</th></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>
<!-- End section: Containing blocks -->
<h2 id="normal-flow"><dfn 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 [[!CSS3BOX]] 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"><dfn 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 'clear' property) or around the floated box. See the CSS 2.1 [[!CSS21]]<!--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"><dfn title="positioning schemes">Positioning schemes</dfn></h2>
<p>In CSS, a box may be laid out according to three positioning schemes:</p>
<ol>
<li>
Normal flow<br>
In CSS, <span>normal flow</span> 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 <span title="relative positioning">relative</span> and <span title="sticky positioning">sticky</span> positioning of block-level and inline-level boxes.
</li>
<li>
Floats<br>
In the <span title="floats">float</span> model, a box is first laid out according to the <span>normal flow</span>, then taken
out of the flow and positioned, typically to the left or right. Content may flow
along the side of a <span title="floats">float</span>.
</li>
<li>
Absolute positioning<br>
In the absolute positioning model, a box is removed from the <span>normal flow</span> entirely
(it has no impact on later siblings) and assigned a position with respect to a
<span>containing block</span>.
</li>
</ol>
<p>
An element is called <em>out-of-flow</em> if it is <span title="floats">floated</span>, 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.
</p>
<h3 id="relative-positioning"><dfn title="relative positioning|relative position|relatively positioned">Relative positioning</dfn></h3>
<p>
Once a box has been laid out according to the <span>normal flow</span> or <span title="floats">floated</span>,
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&#39;s offset
is applied. This implies that relative positioning may cause boxes to overlap. However,
if relative positioning causes an 'overflow: auto' or 'overflow: scroll' 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>
<p>
A relatively positioned box keeps its <span>normal flow</span> size, including line breaks and the
space originally reserved for it.
</p>
<p>
A relatively positioned box establishes a new a new <span>containing block</span> for absolutely
positioned descendants. (This is a common use of relatively positioned boxes.) The
section on <span title="containing block">containing blocks</span>
explains when a relatively positioned box establishes a new <span>containing block</span>.
</p>
<p>
For relatively positioned elements, 'left' and 'right' move the box(es) horizontally,
without changing their size. 'Left' moves the boxes to the right, and 'right' moves
them to the left. Since boxes are not split or stretched as a result of 'left' or
'right', the used values are always: left = -right.
</p>
<p>
If both 'left' and 'right' are ''auto'' (their initial values), the used values are ''0''
(i.e., the boxes stay in their original position).
</p>
<p>
If 'left' is ''auto'', its used value is minus the value of 'right' (i.e., the boxes move
to the left by the value of 'right').
</p>
<p>If 'right' is specified as ''auto'', its used value is minus the value of 'left'.</p>
<p>
If neither 'left' nor 'right' is ''auto'', the position is over-constrained, and one of
them has to be ignored. If the 'direction' property of the <span>containing block</span> is ''ltr'',
the value of 'left' wins and 'right' becomes -'left'. If 'direction' of the containing
block is ''rtl'', 'right' wins and 'left' is ignored.
</p>
<div class="example">
<p>The following three rules are equivalent:</p>
<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 'top' and 'bottom' properties move relatively positioned element(s) up or down
without changing their size. 'Top' moves the boxes down, and 'bottom' moves them up.
Since boxes are not split or stretched as a result of 'top' or 'bottom', the used values
are always: top = -bottom.
</p>
<p>If 'top' and 'bottom' are ''auto'', their used values are both ''0''.</p>
<p>
If one of them, 'top' or 'bottom', is ''auto'', the ''auto'' value becomes the negative of
the other.
</p>
<p>
If neither 'top' and 'bottom' is ''auto'', 'bottom' is ignored (i.e., the used value of
'bottom' will be minus the value of 'top').
</p>
<p class="note">
Note, Although relative positioning could be used as a form of superscripting and subscripting,
the line height is not automatically adjusted to take the positioning into consideration.
See the description of <a href="http://www.w3.org/TR/CSS2/visudet.html#line-height">line height calculations</a> for more information.
</p>
<p>
Examples of relative positioning are provided in the section comparing <span>normal flow</span>,
<span title="floats">floats</span>, and absolute positioning.
</p>
<!-- End section: Relative positioning -->
<h3 id="sticky-positioning"><span class="index-def" title="sticky positioning|sticky position|stickily positioned">Sticky positioning</span></h3>
<p>
A stickily positioned box is positioned similarly to a <span>relatively positioned</span> box, but the
offset is computed with reference to its <span>flow root</span> in addition to the containing block.
</p>
<p>
Specifically, once a box has been laid out according to the <span>normal flow</span>
or <span title="floats">floated</span>, its sticky offset is computed as described below. 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 sticky
positioning may cause boxes to overlap. However, if sticky positioning causes an 'overflow: auto' or
'overflow: scroll' 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>
<p>
A stickily positioned box keeps its <span>normal flow</span> size, including line breaks and the space
originally reserved for it.
</p>
<p>
A stickily positioned box establishes a new a new <span>containing block</span> for absolutely
positioned descendants, just as relative positioning does. The section on
<span title="containing block">containing blocks</span> explains when a stickily positioned box
establishes a new <span>containing block</span>.
</p>
<p>
For stickily positioned elements, 'left', 'right', 'top' and 'bottom' are offsets from the respective
edges of its flow box which are used to constrain the element's offset. Percentage values of 'left' and
'right' refer to the width of its flow box; percentage values of 'top' and 'bottom' refer to the height
of its flow box.
</p>
<p class="issue">Describe which element font-size-relative units are resolved against</p>
<p>
The offset of a stickily positioned box is computed as follows:
</p>
<ol>
<li>
A rectangle is computed relative to the containing block of the stickily positioned element, by
insetting its flow box rectangle on each side by offsets computed from the 'left', 'right', 'top'
and 'bottom' properties of the stickily positioned element.
<p class="issue">Say what happens if this rectangle is empty</p>
</li>
<li>
The intersection is taken between the resulting rectangle, and the containing block of the stickily
positioned element. The result, termed the the <em>sticky-constraint rectangle</em>, is a rectangle
used to constrain the location of the stickily positioned element.
</li>
<li>
If the stickily positioned element's 'top' style is not 'auto', and the stickily positioned element
projects above the top of the <em>sticky-constraint rectangle</em>, the stickily positioned element
is moved down until it is fully contained in the <em>sticky-constraint rectangle</em>.
</li>
<li>
If the stickily positioned element's 'bottom' style is not 'auto', and the stickily positioned
element projects below the bottom of the <em>sticky-constraint rectangle</em>, the stickily
positioned element is moved up until it is fully contained in the <em>sticky-constraint
rectangle</em>.
</li>
<li>
If the stickily positioned element's 'left' style is not 'auto', and the stickily positioned
element projects outside the left of the <em>sticky-constraint rectangle</em>, the stickily
positioned element is moved right until it is fully contained in the <em>sticky-constraint
rectangle</em>.
</li>
<li>
If the stickily positioned element's 'right' style is not 'auto', and the stickily positioned
element projects outside the right of the <em>sticky-constraint rectangle</em>, the stickily
positioned element is moved left until it is fully contained in the <em>sticky-constraint
rectangle</em>.
</li>
</ol>
<p>
When computing containement of the stickily positioned element within its containing block, margins on
the stickily positioned element are taken into account.
</p>
<p class="issue">Say what happens if it already overflows the containing block</p>
<p class="issue">Do marins collapse between the stickily positioned element and its containing block element?</p>
<p>
Intersection between the stickily positioned element and the bottom of the <em>sticky-constraint
rectangle</em> limits movement in any direction, so the offset never pushes the stickily positioned
element outside of its containing block. However, when the element is free to move within its
containing block as the page is scrolled, it appears to be pinned to the relevant flow root edges,
similarly to a fixed position element.
</p>
<p class="note">
Note that a stickily positioned element with non-auto 'top' style and auto 'bottom' style will only
ever be pushed down by sticky positioning; it will never be offset upwards.
</p>
<p class="note">
Multiple stickily positioned elements in the same container are offset independently. Sticky position
offsets may cause them to overlap.
</p>
<p class="issue">
Does the margin on the stickily positioned element affect its distance from the flow root edge?
</p>
<p class="issue">
Sticky positioning should really be defined in terms of the
nearest scrollable ancestor, but there is currently no such
term defined elsewhere in CSS. CSSOM View refers to
"scrolling boxes." CSS Overflow has yet to pull in the
relevant text from CSS Box, and CSS Box has an old,
confusing definition of "flow root" which is almost (but
probably not quite) what we want here. This spec refers
to "flow root," since that's the closest thing currently
specced somewhere, but this is not optimal.
</p>
<div class=example>
<p>
The following example is the same as the previous one, but now it is explained:
</p>
<pre>EM { font-style: italic }</pre>
</div>
<!-- End section: Sticky positioning -->
<h3 id="absolute-positioning"><span class="index-def" title="absolute positioning|absolute position|absolutely positioned">Absolute positioning</span></h3>
<p>
In the absolute positioning model, a box is explicitly offset with respect to its
<span>containing block</span>. It is removed from the <span>normal flow</span> entirely (it has no impact on later
siblings). An absolutely positioned box establishes a new <span>containing block</span> for normal
flow children and absolutely (but not fixed or page) positioned descendants. However, the
contents of an absolutely positioned element do not flow around any other boxes. They
may obscure the contents of another box (or be obscured themselves), depending on the
stack levels of the overlapping boxes.
</p>
<p>
References in this specification to an <span class="index-def" title="absolute positioned element/box">absolutely positioned element</span> (or its box)
imply that the element&#39;s 'position' property has the value <span title="'position'!!''absolute''">''absolute''</span> or <span title="'position'!!''fixed''">''fixed''</span>.
</p>
<!-- End section: Absolute positioning -->
<h3 id="center-positioning"><span class="index-def" title="center positioning|center position|center positioned">Center positioning</span></h3>
<p>
In the center positioning model, a box is explicitly centered with respect to its
<span>containing block</span>. It is removed from the <span>normal flow</span> entirely (it has no impact on later
siblings). A center positioned box establishes a new <span>containing block</span> for <span>normal
flow</span> children and absolutely (but not fixed or page) positioned descendants. However, the
contents of an center positioned element do not flow around any other boxes. They
may obscure the contents of another box (or be obscured themselves), depending on the
stack levels of the overlapping boxes.
</p>
<p>
References in this specification to an <span class="index-def" title="center positioned element/box">center positioned element</span> (or its box)
imply that the element&#39;s 'position' property has the value <span title="'position'!!''center''">''center''</span>.
</p>
<!-- End section: Center positioning -->
<h3 id="page-positioning"><span class="index-def" title="page positioning|page position|page positioned">Page positioning</span></h3>
<p>
In the page positioning model, a box is explicitly offset with respect to its
<span>containing block</span>. It is removed from the <span>normal flow</span> entirely
(it has no impact on later siblings). A page positioned box establishes a new
<span>containing block</span> for <span>normal flow</span> children and absolutely (but
not fixed or other page) positioned descendants. However, the contents of a page
positioned element do not flow around any other boxes. They may obscure the contents of
another box (or be obscured themselves), depending on the stack levels of the
overlapping boxes.
</p>
<p>
For <a href="http://www.w3.org/TR/CSS2/page.html">paged media</a>, boxes with page
positions are only generated on the initial page where the page position element exists.
Boxes with page position that are larger than the page area are clipped and the
remaining part of the box is placed on the following page.
</p>
<p>
References in this specification to a <span class="index-def" title="page positioned element/box">page positioned element</span> (or its box) imply
that the element&#39;s 'position' property has the value <span title="'position'!!''page''">''page''</span>.
</p>
<!-- End section: Page positioning -->
<h3 id="fixed-positioning"><span class="index-def" title="fixed positioning|fixed position|fixed positioned">Fixed positioning</span></h3>
<p>
Fixed positioning is similar to absolute positioning. The only difference is that
for a fixed positioned box, the <span>containing block</span> is established by the <span>viewport</span>.
For <a href="http://www.w3.org/TR/CSS2/media.html#continuous-media-group">continuous media</a>,
fixed boxes do not move when the document is scrolled. In this respect, they are similar
to <a href="http://www.w3.org/TR/CSS2/colors.html#background-properties">fixed background images</a>.
For <a href="http://www.w3.org/TR/CSS2/media.html#paged-media-group">paged media</a>, boxes
with fixed positions are repeated on every page. This is useful for placing, for
instance, a signature at the bottom of each page. Boxes with fixed position that are
larger than the page area are clipped. Parts of the fixed position box that are not
visible in the <span>initial containing block</span> will not print.
</p>
<div class="example">
<p>
Authors may use fixed positioning to create the following presentation:
</p>
<div class="figure">
<p>
<img src="images/frame.png" alt="Example of frame layout">
<span class="dlink"><a id="img-frame" href="images/longdesc/frame-desc.html" title="Long description for frame layout example">[D]</a></span>
<span class="slink">&nbsp;&nbsp;&nbsp;<a id="source-frame" href="source/frame-src.html" title="Source code for frame layout example">[S]</a></span>
</p>
</div>
<p>This might be achieved with the following HTML document and style rules:</p>
<pre><code class="html">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;A frame document with CSS&lt;/title&gt;
&lt;style type="text/css" media="screen"&gt;
body { height: 8.5in } /* Required for percentage heights below */
#header {
position: fixed;
width: 100%;
height: 15%;
top: 0;
right: 0;
bottom: auto;
left: 0;
}
#sidebar {
position: fixed;
width: 10em;
height: auto;
top: 15%;
right: auto;
bottom: 100px;
left: 0;
}
#main {
position: fixed;
width: auto;
height: auto;
top: 15%;
right: 0;
bottom: 100px;
left: 10em;
}
#footer {
position: fixed;
width: 100%;
height: 100px;
top: auto;
right: 0;
bottom: 0;
left: 0;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="header"&gt; ... &lt;/div&gt;
&lt;div id="sidebar"&gt; ... &lt;/div&gt;
&lt;div id="main"&gt; ... &lt;/div&gt;
&lt;div id="footer"&gt; ... &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
</div>
<!-- End section: Fixed positioning -->
<!-- End section: Positioning schemes -->
<h3 id="position-property">Choosing a positioning scheme: 'position' property</h3>
<p>
The 'position' property determines which of the positioning algorithms is used to
calculate the position of a box.
</p>
<table id="propdef-position" class="propdef">
<tr>
<th>Name:</th>
<td><dfn title="'position'">position</dfn></td>
</tr>
<tr>
<th><a href="#values">Value</a>:</th>
<td><var>static</var> | <var>relative</var> | <var>absolute</var> | <var>sticky</var> | <var>center</var> | <var>page</var> | <var>fixed</var></td>
</tr>
<tr>
<th>Initial:</th>
<td>static</td>
</tr>
<tr>
<th>Applies to:</th>
<td>all elements except table-column-group and table-column</td>
</tr>
<tr>
<th>Inherited:</th>
<td>no</td>
</tr>
<tr>
<th>Animatable:</th>
<td>no</td>
</tr>
<tr>
<th>Percentages:</th>
<td>N/A</td>
</tr>
<tr>
<th>Media:</th>
<td>visual</td>
</tr>
<tr>
<th>Computed&nbsp;value:</th>
<td>specified value</td>
</tr>
<tr>
<th>Canonical&nbsp;order:</th>
<td><abbr title="follows order of property value definition">per grammar</abbr></td>
</tr>
</table>
<p>The values of this property have the following meanings:</p>
<dl>
<dt><dfn title="'position'!!''static''">static</dfn></dt>
<dd>
The box is a normal box, laid out according to the <span>normal flow</span>. The
'top', 'right', 'bottom', and 'left' properties do not apply.
</dd>
<dt><dfn title="'position'!!''relative''">relative</dfn></dt>
<dd>
The box&#39;s position is calculated according to the <span>normal flow</span>
(this is called the position in <span>normal flow</span>). Then the box is offset relative
to its normal position and in all cases, including table elements, does not affect
the position of any following boxes. When a box B is relatively positioned, the
position of the following box is calculated as though B were not offset. The effect
of <span title="'position'!!''relative''">'position: relative'</span> on table elements is defined as follows:
<ul>
<li>
table-row-group, table-header-group, table-footer-group and table-row offset
relative to its normal position within the table. If table-cells span
multiple rows, only the cells originating in the <span title="relative positioning">relative positioned</span> row is
offset.
</li>
<li>
table-column-group, table-column do not offset the respective column and has
no visual affect when <span title="'position'!!''relative''">'position: relative'</span> is applied.
</li>
<li>
table-caption and table-cell offset relative to its normal position within
the table. If a table cell spans multiple columns or rows the full spanned
cell is offset.
</li>
</ul>
</dd>
<dt><dfn title="'position'!!''absolute''">absolute</dfn></dt>
<dd>
The box&#39;s position (and possibly size) is specified with the 'top', 'right',
'bottom', and 'left' properties. These properties specify offsets with respect to
the box&#39;s <span>containing block</span>. Absolutely positioned boxes are taken out of the normal
flow. This means they have no impact on the layout of later siblings. Though
absolutely positioned boxes may have margins, those margins do not <a href="http://www.w3.org/TR/CSS2/box.html#collapsing-margins">collapse</a>
with any other margins.
</dd>
<dt><dfn title="'position'!!''sticky''">sticky</dfn></dt>
<dd>
The box&#39;s position is calculated according to the <span>normal flow</span>
(this is called the position in <span>normal flow</span>). Then the box is offset relative
to its flow root and containing block and in all cases, including table elements, does not affect
the position of any following boxes. When a box B is stickily positioned, the
position of the following box is calculated as though B were not offset. The effect
of <span title="'position'!!''sticky''">'position: sticky'</span> on table elements is the same as
for <span title="'position'!!''relative''">'position: relative'</span>
</dd>
<dt><dfn title="'position'!!''center''">center</dfn></dt>
<dd>
The box&#39;s position (and possibly size) is specified with the 'top', 'right',
'bottom', and 'left' properties. The box is vertically and horizontally centered
within its <span>containing block</span> and these properties specify offsets with respect to
the box&#39;s centered position within its <span>containing block</span>. Center
positioned boxes are taken out of the normal flow. This means they have no impact on
the layout of later siblings. Though center positioned boxes may have margins, those
margins do not <a href="http://www.w3.org/TR/CSS2/box.html#collapsing-margins">collapse</a>
with any other margins.
</dd>
<dt><dfn title="'position'!!''page''">page</dfn></dt>
<dd>
<p>The box&#39;s position is calculated according to the "absolute" model.</p>
<ul>
<li>
In the case of paged media or when inside a region box the box&#39;s
<span>containing block</span> is always the <span>initial containing block</span>.
</li>
<li>
Otherwise, the <span>containing block</span> is determined per the
"absolute" model.
</li>
</ul>
<p>
As with the "absolute" model, the box&#39;s margins do not collapse with any
other margins. In the case of the print media type, the box is rendered only on
the initial page or region where the page positioned element originated. User
agents may paginate the content of paged boxes.
</p>
<p class="note">
Note, that CSS Regions are also <span title="initial containing block">initial containing blocks</span>, in accordance with
<a href="http://dev.w3.org/csswg/css3-regions/#flow-into">'flow-into'</a> property
of the CSS Regions Module [[!CSS3-REGIONS]].
</p>
</dd>
<dt><dfn title="'position'!!''fixed''">fixed</dfn></dt>
<dd>
The box&#39;s position is calculated according to the "absolute" model, but in addition,
the box is fixed with respect to some reference. As with the "absolute" model, the
box&#39;s margins do not collapse with any other margins. In the case of handheld,
projection, screen, tty, and tv media types, the box is fixed with respect to the
<span>viewport</span> and does not move when scrolled. In the case of the print media type, the
box is rendered on every page, and is fixed with respect to the page box, even if
the page is seen through a <span>viewport</span> (in the case of a print-preview, for example).
For other media types, the presentation is undefined. Authors may wish to specify
<span title="'position'!!''fixed''">''fixed''</span> in a media-dependent way. For instance, an author may want a box to remain
at the top of the <span>viewport</span> on the screen, but not at the top of each printed page.
The two specifications may be separated by using an <a href="http://www.w3.org/TR/CSS2/media.html#at-media-rule">'@media'</a>
rule, as in:
<div class="example">
<pre><code class="css">
@media screen {
h1#first { position: fixed }
}
@media print {
h1#first { position: static }
}
</code></pre>
</div>
<p>User agents must not paginate the content of fixed boxes.</p>
<p class="note">
Note that user agents may print invisible content in other ways. See
<a href="http://www.w3.org/TR/CSS2/page.html#outside-page-box">"Content outside the page box"</a>.
</p>
</dd>
</dl>
<p>
In previous versions of CSS user agents may treat position <span title="'position'!!''fixed''">''fixed''</span> as <span title="'position'!!''static''">''static''</span> on
the root element. This specification removes that option and it is now required that
newer user agents treat <span title="'position'!!''fixed''">''fixed''</span> value on the root element as defined for all other
elements.
</p>
<!-- End section: Choosing a positioning scheme: 'position' property -->
<h3 id="box-offsets-trbl">Box offsets: 'top', 'right', 'bottom', 'left'</h3>
<p>
An element is said to be <span class="index-def" title="positioned element/box">positioned</span> if its 'position' property has a value
other than <span title="'position'!!''static''">''static''</span>. Positioned elements generate positioned boxes, and may be laid out according
to the following four physical properties:
</p>
<table id="propdef-top" class="propdef">
<tr>
<th>Name:</th>
<td><dfn title="'top'">top</dfn></td>
</tr>
<tr>
<th><a href="#values">Value</a>:</th>
<td><var>auto</var> | <var>&lt;length&gt;</var> | <var>&lt;percentage&gt;</var></td>
</tr>
<tr>
<th>Initial:</th>
<td>auto</td>
</tr>
<tr>
<th>Applies to:</th>
<td>positioned elements</td>
</tr>
<tr>
<th>Inherited:</th>
<td>no</td>
</tr>
<tr>
<th>Animatable:</th>
<td>&lt;length&gt;, &lt;percentage&gt;</td>
</tr>
<tr>
<th>Percentages:</th>
<td>refer to height of <span>containing block</span></td>
</tr>
<tr>
<th>Media:</th>
<td>visual</td>
</tr>
<tr>
<th>Computed&nbsp;value:</th>
<td>
for <span title="'position'!!''relative''">'position: relative'</span>, see <span title="relative positioning">Relative positioning</span>.
For <span title="'position'!!''sticky''">'position: sticky'</span>, see <span title="sticky positioning">Sticky positioning</span>.
For <span title="'position'!!''static''">'position: static'</span>,
''auto''. Otherwise: if specified as a '&lt;length&gt;', the corresponding absolute length;
if specified as a '&lt;percentage&gt;', the specified value; otherwise, ''auto''.
</td>
</tr>
<tr>
<th>Canonical&nbsp;order:</th>
<td><abbr title="follows order of property value definition">per grammar</abbr></td>
</tr>
</table>
<p>
This property specifies how far an absolutely positioned box&#39;s top margin edge is
offset below the top edge of the box&#39;s <span>containing block</span>.
</p>
<p>
For relatively positioned boxes, the offset is with respect to the top edge of the box
itself (i.e., the box is given a position in the <span>normal flow</span>, and then
offset from that position according to this property).
</p>
<p>