css-position/Overview.bs

Sun, 31 Jan 2016 15:42:31 -0800

author
Peter Linss <[email protected]>
date
Sun, 31 Jan 2016 15:42:31 -0800
changeset 16986
5be73fbc8592
parent 16542
27d9df21dcba
child 16989
255258410d1b
permissions
-rw-r--r--

change //dev.w3.org/csswg/ urls to //drafts.csswg.org/

     1 <h1>CSS Positioned Layout Module Level 3</h1>
     3 <pre class='metadata'>
     4 Status: ED
     5 Work Status: Exploring
     6 Shortname: css-position
     7 Level: 1
     8 Group: csswg
     9 ED: https://drafts.csswg.org/css-position/
    10 TR: http://www.w3.org/TR/css3-positioning/
    11 Previous Version: http://www.w3.org/TR/2015/WD-css3-positioning-20150203/
    12 Previous Version: http://www.w3.org/TR/2012/WD-css3-positioning-20120207/
    13 Editor: Rossen Atanassov, Microsoft, [email protected]
    14 Editor: Arron Eicholz, Microsoft, [email protected]
    15 !Issues list: <a href="http://wiki.csswg.org/spec/css-position/">in Wiki</a>
    16 Abstract: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, the ability to specify different containing blocks for elements and sticky positioning. <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.
    17 Ignored Terms: div, dl, dfn, attachment-type, attachment-top, attachment-right, attachment-bottom, attachment-left, attachment, scrolling box
    18 Link Defaults: css-transforms-1 (property) transform
    19 </pre>
    21 <style type="text/css">
    22   .cb-example-table {
    23     border: 1px solid;
    24     border-collapse: collapse;
    25     font-size: smaller;
    26     text-align: center;
    27     margin: 0 2em;
    28   }
    29   .cb-example-table td, .cb-example-table th {
    30     border: 1px solid;
    31     padding: 0 3px;
    32   }
    33   code span, td span {
    34     white-space: nowrap;
    35   }
    36   .relationship-table {
    37     border: 1px solid;
    38     border-collapse: collapse;
    39     font-size: smaller;
    40     margin: 0 6em;
    41   }
    42   .relationship-table th {
    43     text-align: center;
    44     white-space:nowrap;
    45   }
    46   .relationship-table td, .relationship-table th {
    47     border: 1px solid;
    48     padding: 0 3px;
    49   }
    50   h2 dfn, h3 dfn {
    51     font: inherit;
    52   }
    54   table.lpr {
    55     border-collapse: collapse;
    56   }
    57   .lpr td, .lpr th {
    58     border: 1px solid;
    59     text-align: center;
    60   }
    61   .lpr col {
    62     background: rgb(221, 238, 255);
    63     border-right: 2px solid;
    64     font-weight: bold;
    65     padding: 0 5px;
    66   }
    67   .lpr div {
    68     font-weight: bold;
    69     -moz-transform: rotate(-90deg) translatex(-0.5em);
    70     -ms-transform: rotate(-90deg) translatex(-0.5em);
    71     -o-transform: rotate(-90deg) translatex(-0.5em);
    72     -webkit-transform: rotate(-90deg) translatex(-0.5em);
    73     transform: rotate(-90deg) translatex(-0.5em);
    74     width: 1.5em;
    75   }
    76   .lpr th:first-child {
    77     border: none;
    78     background: white;
    79   }
    80   .lpr tbody td:first-child {
    81     font-weight: normal;
    82   }
    83   .lpr thead td {
    84     background: rgb(238, 238, 238);
    85     font-weight: bold;
    86     padding: 0 5px;
    87     vertical-align: bottom;
    88     white-space: nowrap;
    89   }
    90   .lpr thead tr:nth-child(2) {
    91     border-bottom: 2px solid;
    92   }
    93 </style>
    95 <h2 id="intro">
    96 Introduction</h2>
    97   <em>This section is not normative.</em>
    99   CSS assumes the document layout is modeled as a tree of elements. The unique
   100   element that has no parent is called the root element. This module describes
   101   how any of the elements from the tree of elements can be arranged independent
   102   of document order (i.e. taken out of "flow"). With a positioned element the
   103   element may be placed anywhere within the content not specifically respecting
   104   the tree of elements order.
   107   In [[!CSS21]], the visual formatting model explained how each element in the
   108   document tree generates zero or more boxes according to the box model. This
   109   module further explains and extends the positioning scheme. The layout of
   110   these boxes is governed by:
   112   <ul>
   113     <li>
   114       <a href="http://www.w3.org/TR/CSS2/box.html#box-dimensions">box dimensions</a>
   115       and <a href="http://www.w3.org/TR/CSS2/visuren.html#box-gen">type</a>.
   116     <li>
   117       positioning scheme (<a>normal flow</a>, float, and absolute positioning).
   118     <li>
   119       relationships between elements in the
   120       <a href="http://www.w3.org/TR/CSS2/conform.html#doctree">document tree</a>.
   121     <li>
   122       external information (e.g., viewport size, intrinsic dimensions of images, etc.).
   123   </ul>
   125   The properties defined in this module apply to both continuous media and paged
   126   media.
   128 <h3 id="placement">
   129 Module Interactions</h3>
   131   This module replaced and extends the positioning scheme features defined in
   132   [[!CSS21]] sections:
   134   <ul>
   135     <li>
   136     <a href="http://www.w3.org/TR/CSS2/visuren.html#viewport">9.1.1 The viewport</a>
   137     <li>
   138     <a href="http://www.w3.org/TR/CSS2/visuren.html#containing-block">9.1.2 Containing blocks</a>
   139     <li>
   140     <a href="http://www.w3.org/TR/CSS2/visuren.html#positioning-scheme">9.3 Positioning schemes</a>
   141     <li>
   142     <a href="http://www.w3.org/TR/CSS2/visuren.html#relative-positioning">9.4.3 Relative positioning</a>
   143     <li>
   144     <a href="http://www.w3.org/TR/CSS2/visuren.html#absolute-positioning">9.6 Absolute positioning</a>
   145     <li>
   146     <a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">9.7 Relationships between display, position, and float</a>
   147     <li>
   148     <a href="http://www.w3.org/TR/CSS2/visuren.html#comparison">9.8 Comparison of normal flow, floats, and absolute positioning</a>
   149     <li>
   150     <a href="http://www.w3.org/TR/CSS2/visuren.html#layers">9.9 Layered presentation</a>
   151     <li>
   152     <a href="http://www.w3.org/TR/CSS2/visudet.html#containing-block-details">10.1 Definition of "containing block"</a>
   153     <li>
   154     <a href="http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width">10.3.7 Absolutely positioned, non-replaced elements</a>
   155     <li>
   156     <a href="http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-width">10.3.8 Absolutely positioned, replaced elements</a>
   157     <li>
   158     <a href="http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-height">10.6.4 Absolutely positioned, non-replaced elements</a>
   159     <li>
   160     <a href="http://www.w3.org/TR/CSS2/visudet.html#abs-replaced-height">10.6.5 Absolutely positioned replaced elements</a>
   161     <li>
   162     <a href="http://www.w3.org/TR/CSS2/visudet.html#root-height">10.6.7 Auto heights for block formatting context roots</a>
   163     <li>
   164     <a href="http://www.w3.org/TR/CSS2/zindex.html">Appendix E. Elaborate description of Stacking Contexts</a>
   165   </ul>
   167 <!-- End section" Module Interactions -->
   169 <h3 id="values">
   170 Values</h3>
   172   This specification follows the CSS property definition conventions from [[!CSS21]].
   174   Value types not defined in this specification are defined in CSS Level 2
   175   Revision 1 [[!CSS21]]. Other CSS modules may expand the definitions of these
   176   value types: for example [[!CSS3VAL]], when combined with this module, expands
   177   the definition of the &lt;length> value type as used in this specification.
   180   In addition to the property-specific values listed in their definitions, all
   181   properties defined in this specification also accept the
   182   <a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
   183   keyword as their property value. For readability it has not been repeated
   184   explicitly.
   186 <!-- End section: Values -->
   187 <!-- End section Introduction -->
   189 <h2 id="vp">
   190 The <dfn lt="viewport">Viewport</dfn></h2>
   192     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
   193     viewing area on the screen) through which users consult a document. User
   194     agents may change the document’s layout when the viewport is resized
   195     (see the <span>initial containing block</span>).
   197     When the viewport is smaller than the area of the canvas on which the document
   198     is rendered, the user agent may offer a scrolling mechanism. There is at most
   199     one viewport per <a href="http://www.w3.org/TR/CSS2/intro.html#canvas">canvas</a>,
   200     but user agents may render to more than one canvas (i.e., provide different
   201     views of the same document).
   203 <!-- End section: The Viewport -->
   205 <h2 id="cb">
   206 Containing Blocks</h2>
   208   In CSS, many box positions and sizes are calculated with respect to the edges
   209   of a rectangular box called a containing block. In general, generated boxes
   210   act as containing blocks for descendant boxes; we say that a box "establishes"
   211   the containing block for its descendants. The phrase "a box’s containing
   212   block" means "the containing block in which the box lives," not the one it
   213   generates.
   216   Each box is given a position with respect to its containing block, but it is
   217   not confined by this containing block; it may
   218   <a href="http://www.w3.org/TR/CSS2/visufx.html#overflow">overflow</a>.
   221 <h3 id="def-cb">
   222 Definition of <dfn lt="containing block">containing block</dfn></h3>
   224   The position and size of an element’s box(es) are sometimes computed relative
   225   to a certain rectangle, called the containing block of the element. The containing
   226   block of a ''position/static'' or
   227   ''position/relative'' element is defined
   228   in the Box Model [[!CSS3BOX]]. The containing block of a
   229   ''position/sticky'' element is the same as for a
   230   ''position/relative'' element. For
   231   ''position/fixed'' and
   232   ''position/absolute'', it is defined as follows:
   234   <ol>
   235     <li>
   236     If the element has ''position: fixed'', the containing block is established by the
   237     <a>viewport</a> in the case of continuous media or the page area in
   238     the case of paged media.
   240     <li>
   241     If the element has ''position: absolute'',
   242     the containing block is established by the nearest ancestor with a 'position'
   243     other than ''position/static'', in the following way:
   244     <ol>
   245       <li>
   246       In the case that the ancestor is block-level, the containing block is formed
   247       by the padding edge of the ancestor.
   249       <li>
   250       In the case that the ancestor is inline-level, the containing block depends
   251       on the 'direction' property of the ancestor:
   252       <ol>
   253         <li>
   254           If the 'direction' is ''ltr'', the top and left of the containing
   255           block are the top and left content edges of the first box generated
   256           by the ancestor, and the bottom and right are the bottom and right
   257           content edges of the last box of the ancestor.
   259         <li>
   260         If the 'direction' is ''rtl'', the top and right are the
   261         top and right edges of the first box generated by the ancestor, and
   262         the bottom and left are the bottom and left content edges of the
   263         last box of the ancestor.
   264         <p class="note">
   265           Note, in some cases when a line wraps it may seem as if the left
   266           and right positions are swapped.
   267         </p>
   268       </ol>
   269     </ol>
   270     <li>
   272     <li>
   273     If there is no such ancestor, the containing block is the <a>initial
   274     containing block</a>.
   275   </ol>
   277   In paged media, an absolutely positioned element is positioned relative to its
   278   containing block ignoring any page breaks (as if the document were continuous). The
   279   element may subsequently be broken over several pages.
   281   For absolutely positioned content that resolves to a position on a page other than the
   282   page being laid out (the current page), or resolves to a position on the current page
   283   which has already been rendered for printing, printers may place the content:
   285   <ul>
   286     <li>on the current page,</li>
   287     <li>on a subsequent page, or</li>
   288     <li>may omit it altogether.</li>
   289   </ul>
   291 <p class="note">
   292   Note, a block-level element that is split over several pages may have a different width
   293   on each page and that there may be device-specific limits.
   294 </p>
   296 <div class="example">
   298   With no positioning, the containing blocks (C.B.) in the following document:
   300 <pre><code class="html">
   301 &lt;!DOCTYPE html>
   302 &lt;html>
   303     &lt;head>
   304         &lt;title>Illustration of containing blocks&lt;/title>
   305     &lt;/head>
   306     &lt;body id="body">
   307         &lt;div id="div1">
   308         &lt;p id="p1">This is text in the first paragraph...&lt;/p>
   309         &lt;p id="p2">This is text &lt;em id="em1"> in the
   310         &lt;strong id="strong1">second&lt;/strong> paragraph.&lt;/em>&lt;/p>
   311         &lt;/div>
   312     &lt;/body>
   313 &lt;/html>
   314 </code></pre>
   316   are established as follows:
   318 <table class="cb-example-table">
   319   <tr><th>For box generated by </th>
   320   <th>C.B. is established by</th></tr>
   321   <tr><td>html</td><td>initial C.B. (UA-dependent)</td></tr>
   322   <tr><td>body</td><td>html</td></tr>
   323   <tr><td>div1</td><td>body</td></tr>
   324   <tr><td>p1</td><td>div1</td></tr>
   325   <tr><td>p2</td><td>div1</td></tr>
   326   <tr><td>em1</td><td>p2</td></tr>
   327   <tr><td>strong1</td><td>p2</td></tr>
   328 </table>
   330   If we position "div1":
   332 <pre><code class="css">
   333 #div1 { position: absolute; left: 50px; top: 50px }
   334 </code></pre>
   336   its containing block is no longer "body"; it becomes the <span>initial containing block</span>
   337   (since there are no other positioned ancestor boxes).
   339   If we position "em1" as well:
   341 <pre><code class="css">
   342 #div1 { position: absolute; left: 50px; top: 50px }
   343 #em1  { position: absolute; left: 100px; top: 100px }
   344 </code></pre>
   346   the table of containing blocks becomes:
   348   <table class="cb-example-table">
   349     <tr><th>For box generated by</th>
   350     <th>C.B. is established by</th></tr>
   351     <tr><td>html</td><td>initial C.B. (UA-dependent)</td></tr>
   352     <tr><td>body</td><td>html</td></tr>
   353     <tr><td>div1</td><td>initial C.B.</td></tr>
   354     <tr><td>p1</td><td>div1</td></tr>
   355     <tr><td>p2</td><td>div1</td></tr>
   356     <tr><td>em1</td><td>div1</td></tr>
   357     <tr><td>strong1</td><td>em1</td></tr>
   358   </table>
   360   By positioning "em1", its containing block becomes the nearest positioned ancestor box
   361   (i.e., that generated by "div1").
   362 </div>
   364 <!-- End section: Containing blocks -->
   366 <h2 id="nf">
   367 <dfn>Normal Flow</dfn></h2>
   369   Boxes in the normal flow belong to a formatting context, which may be block or
   370   inline, but not both simultaneously. See the CSS Basic Box Model module
   371   [[!CSS3BOX]] for further details about <a href="http://www.w3.org/TR/CSS2/visuren.html#normal-flow">normal flow</a>.
   373 <!-- End section: Normal Flow -->
   375 <h2 id="floats">
   376 <dfn lt="float|floated box|floating box">Floats</dfn></h2>
   378   A float is a box that is positioned within content, often left or right on the
   379   current line. The most interesting characteristic of a float (or "floated" or
   380   "floating" box) is that inline-level content may flow along its side (or be
   381   prohibited from doing so by the 'clear' property) or around the floated box.
   382   See the CSS 2.1 [[!CSS21]]<!--CSS Floats module [[!CSS3FLOATS]]--> for details
   383   about <a href="http://www.w3.org/TR/CSS2/visuren.html#floats">floating boxes</a>.
   385 <!-- End section: Floats -->
   387 <h2 id="pos-sch">
   388 <dfn>Positioning schemes</dfn></h2>
   390   In CSS, a box may be laid out according to three positioning schemes:
   391   <ol>
   392     <li>
   393     Normal flow<br>
   394     In CSS, <a>normal flow</a> includes <a href="http://www.w3.org/TR/CSS2/visuren.html#block-formatting">block formatting</a> of block-level boxes,
   395     <a href="http://www.w3.org/TR/CSS2/visuren.html#inline-formatting">inline formatting</a> of inline-level boxes,
   396     and <a lt="relative positioning" spec="css21">relative</a> and <a lt="sticky positioning">sticky</a> positioning of block-level and inline-level boxes.
   398     <li>
   399     Floats<br>
   400     In the <a>float</a> model, a box is first laid out according to the <a>normal flow</a>, then taken
   401     out of the flow and positioned, typically to the left or right. Content may flow
   402     along the side of a <a>float</a>.
   404     <li>
   405     Absolute positioning<br>
   406     In the absolute positioning model, a box is removed from the <span>normal
   407     flow</span> entirely (it has no impact on later siblings) and assigned a
   408      position with respect to a <a>containing block</a>.
   409   </ol>
   411   An element is called <em>out-of-flow</em> if it is <a>floated</a>, absolutely positioned, or is the root element. An element is called
   412   <em>in-flow</em> if it is not out-of-flow. The <em>flow of an element</em>
   413   A is the set consisting of A and all in-flow elements whose nearest
   414   out-of-flow ancestor is A.
   416 <h3 id="rel-pos">
   417 Relative positioning</h3>
   419   Once a box has been laid out according to the <a>normal flow</a> or
   420   <a>floated</a>, it may be offset relative to this position.
   421   This is called <dfn export lt="relative position|relatively position|relpos">relative positioning</dfn>. Offsetting a box (B1) in this way has no
   422   effect on the box (B2) that follows: B2 is given a position as if B1 were not
   423   offset and B2 is not re-positioned after B1’s offset is applied. This
   424   implies that relative positioning may cause boxes to overlap. However, if
   425   relative positioning causes an 'overflow: auto' or 'overflow: scroll' box to
   426   have overflow, the user agent must allow the user to access this content (at
   427   its offset position), which, through the creation of a scrolling mechanism,
   428   may affect layout.
   430   A relatively positioned box keeps its <a>normal flow</a> size, including
   431   line breaks and the space originally reserved for it.
   433   A relatively positioned box establishes a new a new <a>containing block</a> for
   434   absolutely positioned descendants. (This is a common use of relatively positioned
   435   boxes.) The section on <a>containing blocks</a>
   436   explains when a relatively positioned box establishes a new <a>containing block</a>.
   438   For relatively positioned elements, 'left' and 'right' move the box(es) horizontally,
   439   without changing their size. 'Left' moves the boxes to the right, and 'right' moves
   440   them to the left. Since boxes are not split or stretched as a result of 'left' or
   441   'right', the used values are always: left = -right.
   443   If both 'left' and 'right' are <css>auto</css> (their initial values), the used values
   444   are ''0'' (i.e., the boxes stay in their original position).
   446   If 'left' is <css>auto</css>, its used value is minus the value of 'right' (i.e., the
   447   boxes move to the left by the value of 'right').
   449   If 'right' is specified as <css>auto</css>, its used value is minus the value of 'left'.
   451   If neither 'left' nor 'right' is <css>auto</css>, the position is over-constrained, and
   452   one of them has to be ignored. If the 'direction' property of the <a>containing
   453   block</a> is ''ltr'', the value of 'left' wins and 'right' becomes -'left'.
   454   If 'direction' of the containing block is ''rtl'', 'right' wins and 'left' is
   455   ignored.
   457 <div class="example">
   459   The following three rules are equivalent:
   461 <pre><code class="css">
   462 div.a8 { position: relative; direction: ltr; left: -1em; right: auto }
   463 div.a8 { position: relative; direction: ltr; left: auto; right: 1em }
   464 div.a8 { position: relative; direction: ltr; left: -1em; right: 5em }
   465 </code></pre>
   466 </div>
   468   The 'top' and 'bottom' properties move relatively positioned element(s) up or
   469   down without changing their size. 'Top' moves the boxes down, and 'bottom' moves
   470   them up. Since boxes are not split or stretched as a result of 'top' or 'bottom',
   471   the used values are always: top = -bottom.
   473   If 'top' and 'bottom' are <css>auto</css>, their used values are both ''0''.
   475   If one of them, 'top' or 'bottom', is <css>auto</css>, the <css>auto</css> value becomes the
   476   negative of the other.
   478   If neither 'top' and 'bottom' is <css>auto</css>, 'bottom' is ignored (i.e., the used
   479   value of 'bottom' will be minus the value of 'top').
   481   <p class="note">
   482     Note, Although relative positioning could be used as a form of superscripting
   483     and subscripting, the line height is not automatically adjusted to take the
   484     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
   485     information.
   486   </p>
   488   Examples of relative positioning are provided in the section comparing <a>normal
   489   flow</a>, <a>floats</a>, and absolute positioning.
   491 <!-- End section: Relative positioning  -->
   493 <h3 id="sticky-pos">
   494 Sticky positioning</h3>
   496   A <dfn export lt="sticky position|stickily position|stickypos">stickily positioned</dfn> box is positioned similarly to a <a>relatively
   497   positioned</a> box, but the offset is computed with reference to the nearest
   498   ancestor with a <a>scrolling box</a>, or the viewport if no ancestor has
   499   a <a>scrolling box</a>.
   501   Specifically, once a box has been laid out according to the <a>normal flow</a>
   502   or <a>floated</a>, its sticky offset is computed as described
   503   below. Offsetting a box (B1) in this way has no effect on the box (B2) that
   504   follows: B2 is given a position as if B1 were not offset and B2 is not re-positioned
   505   after B1’s offset is applied. This implies that sticky positioning may cause
   506   boxes to overlap. However, if sticky positioning causes an ''overflow: auto'' or
   507   ''overflow: scroll'' box to have overflow, the user agent must allow the user to
   508   access this content (at its offset position), which, through the creation of a
   509   scrolling mechanism, may affect layout.
   511   A stickily positioned box keeps its <a>normal flow</a> size, including  line
   512   breaks and the space originally reserved for it.
   514   A stickily positioned box establishes a new a new <a>containing block</a> for
   515   absolutely positioned descendants, just as relative positioning does. The section
   516   on <a>containing blocks</a> explains when a
   517   stickily positioned box establishes a new <a>containing block</a>.
   519   For stickily positioned elements, 'left', 'right', 'top' and 'bottom' are
   520   offsets from the respective edges of its flow box which are used to constrain
   521   the element's offset. Percentage values of 'left' and 'right' refer to the
   522   width of its flow box; percentage values of 'top' and 'bottom' refer to the
   523   height of its flow box.
   525   <p class="issue">
   526     Describe which element font-size-relative units are resolved against
   527   </p>
   529   The offset of a stickily positioned box is computed as follows:
   531 <ol>
   532   <li>
   533   A rectangle is computed relative to the containing block of the stickily
   534   positioned element, by insetting its flow box rectangle on each side by offsets
   535   computed from the 'left', 'right', 'top' and 'bottom' properties of the stickily
   536   positioned element.
   537   <p class="issue">
   538     Say what happens if this rectangle is empty
   539   </p>
   541   <li>
   542   The intersection is taken between the resulting rectangle, and the containing
   543   block of the stickily positioned element. The result, termed the the
   544   <em>sticky-constraint rectangle</em>, is a rectangle used to constrain the
   545   location of the stickily positioned element.
   547   <li>
   548   If the stickily positioned element's 'top' style is not <css>auto</css>, and the stickily
   549   positioned element projects above the top of the <em>sticky-constraint
   550   rectangle</em>, the stickily positioned element is moved down until it is fully
   551   contained in the <em>sticky-constraint rectangle</em>.
   553   <li>
   554   If the stickily positioned element's 'bottom' style is not <css>auto</css>, and the stickily
   555   positioned element projects below the bottom of the <em>sticky-constraint
   556   rectangle</em>, the stickily positioned element is moved up until it is fully
   557   contained in the <em>sticky-constraint rectangle</em>.
   559   <li>
   560   If the stickily positioned element's 'left' style is not <css>auto</css>, and the stickily
   561   positioned element projects outside the left of the <em>sticky-constraint
   562   rectangle</em>, the stickily positioned element is moved right until it is fully
   563   contained in the <em>sticky-constraint rectangle</em>.
   565   <li>
   566   If the stickily positioned element's 'right' style is not <css>auto</css>, and the stickily
   567   positioned element projects outside the right of the <em>sticky-constraint
   568   rectangle</em>, the stickily positioned element is moved left until it is fully
   569   contained in the <em>sticky-constraint rectangle</em>.
   570 </ol>
   572   When computing containement of the stickily positioned element within its
   573   containing block, margins on the stickily positioned element are taken into
   574   account.
   576   <p class="issue">
   577     Say what happens if it already overflows the containing block
   578   </p>
   579   <p class="issue">
   580     Do marins collapse between the stickily positioned element and its containing
   581     block element?
   582   </p>
   584   Intersection between the stickily positioned element and the bottom of the
   585   <em>sticky-constraint rectangle</em> limits movement in any direction, so the
   586   offset never pushes the stickily positioned element outside of its containing
   587   block. However, when the element is free to move within its containing block
   588   as the page is scrolled, it appears to be pinned to the relevant flow root
   589   edges, similarly to a fixed position element.
   591   <p class="note">
   592     Note that a stickily positioned element with non-auto 'top' style and auto
   593     'bottom' style will only ever be pushed down by sticky positioning; it will
   594     never be offset upwards.
   595   </p>
   596   <p class="note">
   597     Multiple stickily positioned elements in the same container are offset
   598     independently. Sticky position offsets may cause them to overlap.
   599   </p>
   600   <p class="issue">
   601     Does the margin on the stickily positioned element affect its distance from
   602     the flow root edge?
   603   </p>
   604   <p class="issue">
   605     Sticky positioning should really be defined in terms of the nearest scrollable
   606     ancestor, but there is currently no such term defined elsewhere in CSS. CSSOM
   607     View refers to "scrolling boxes." CSS Overflow has yet to pull in the relevant
   608     text from CSS Box, and CSS Box has an old, confusing definition of "flow root"
   609     which is almost (but probably not quite) what we want here. This spec refers
   610     to "flow root," since that's the closest thing currently specced somewhere,
   611     but this is not optimal.
   612   </p>
   613 <div class=example>
   614   The following example is the same as the previous one, but now it is explained:
   616   <pre>EM { font-style: italic }</pre>
   617 </div>
   618 <!-- End section: Sticky positioning  -->
   620 <h3 id="abs-pos">
   621 Absolute positioning</h3>
   623   In the absolute positioning model, a box is explicitly offset with respect to
   624   its <a>containing block</a>. It is removed from the <a>normal flow</a> entirely
   625   (it has no impact on later siblings). An absolutely positioned box establishes
   626   a new <a>containing block</a> for normal flow children and absolutely (but not
   627   fixed) positioned descendants. However, the contents of an absolutely
   628   positioned element do not flow around any other boxes. They may obscure the
   629   contents of another box (or be obscured themselves), depending on the stack
   630   levels of the overlapping boxes.
   632   References in this specification to an absolutely positioned element (or its
   633   box) imply that the element’s 'position' property has the value
   634   ''absolute'' or ''fixed''.
   635 <!-- End section: Absolute positioning -->
   637 <h3 id="fixed-pos">
   638 Fixed positioning</h3>
   640   Fixed positioning is similar to absolute positioning. The only difference is
   641   that for a fixed positioned box, the <a>containing block</a> is established
   642   by the <a>viewport</a>. For <a href="http://www.w3.org/TR/CSS2/media.html#continuous-media-group">continuous media</a>,
   643   fixed boxes do not move when the document is scrolled. In this respect, they are similar
   644   to <a href="http://www.w3.org/TR/CSS2/colors.html#background-properties">fixed background images</a>.
   645   For <a href="http://www.w3.org/TR/CSS2/media.html#paged-media-group">paged
   646   media</a>, boxes with fixed positions are repeated on every page. This is useful
   647   for placing, for instance, a signature at the bottom of each page. Boxes with
   648   fixed position that are larger than the page area are clipped. Parts of the
   649   fixed position box that are not visible in the <span>initial containing
   650   block</span> will not print.
   652 <div class="example">
   654   Authors may use fixed positioning to create the following presentation:
   656   <figure>
   657     <img src="images/frame.png" alt="Example of frame layout">
   658     <figcaption>
   659       A page layout with a static header and footer at the top and bottom,
   660       a sidebar to one side,
   661       and main content filling the remaining center space.
   662     </figcaption>
   663   </figure>
   665   This might be achieved with the following HTML document and style rules:
   667   <pre class="lang-html">
   668   &lt;!DOCTYPE html>
   669   &lt;html>
   670     &lt;head>
   671       &lt;title>A frame document with CSS&lt;/title>
   672       &lt;style type="text/css" media="screen">
   673         body { height: 8.5in } /* Required for percentage heights below */
   674         #header {
   675           position: fixed;
   676           width: 100%;
   677           height: 15%;
   678           top: 0;
   679           right: 0;
   680           bottom: auto;
   681           left: 0;
   682         }
   683         #sidebar {
   684           position: fixed;
   685           width: 10em;
   686           height: auto;
   687           top: 15%;
   688           right: auto;
   689           bottom: 100px;
   690           left: 0;
   691         }
   692         #main {
   693           position: fixed;
   694           width: auto;
   695           height: auto;
   696           top: 15%;
   697           right: 0;
   698           bottom: 100px;
   699           left: 10em;
   700         }
   701         #footer {
   702           position: fixed;
   703           width: 100%;
   704           height: 100px;
   705           top: auto;
   706           right: 0;
   707           bottom: 0;
   708           left: 0;
   709         }
   710       &lt;/style>
   711     &lt;/head>
   712     &lt;body>
   713       &lt;div id="header"> ...  &lt;/div>
   714       &lt;div id="sidebar"> ...  &lt;/div>
   715       &lt;div id="main"> ...  &lt;/div>
   716       &lt;div id="footer"> ...  &lt;/div>
   717     &lt;/body>
   718   &lt;/html>
   719   </pre>
   720 </div>
   722 <!-- End section: Fixed positioning -->
   723 <!-- End section: Positioning schemes -->
   725 <h3 id="position-property">
   726 Choosing a positioning scheme: 'position' property</h3>
   728   The 'position' property determines which of the positioning algorithms is used to
   729   calculate the position of a box.
   731   <pre class="propdef">
   732   Name: position
   733   Value: static | relative | absolute | sticky | fixed
   734   Initial: static
   735   Applies to: all elements except table-column-group and table-column
   736   Inherited: no
   737   Animatable: no
   738   Percentages: N/A
   739   Media: visual
   740   Computed value: specified value
   741   </pre>
   743   The values of this property have the following meanings:
   744 <dl dfn-for="position" dfn-type="value">
   745   <dt><dfn>static</dfn></dt>
   746   <dd>
   747     The box is a normal box, laid out according to the <a>normal flow</a>. The
   748     'top', 'right', 'bottom', and 'left' properties do not apply.
   750   <dt><dfn>relative</dfn></dt>
   751   <dd>
   752     The box’s position is calculated according to the <a>normal flow</a> (this
   753     is called the position in <a>normal flow</a>). Then the box is offset relative
   754     to its normal position and in all cases, including table elements, does not affect
   755     the position of any following boxes. When a box B is relatively positioned, the
   756     position of the following box is calculated as though B were not offset. The effect
   757     of ''position: relative'' on table elements is defined as follows:
   758     <ul>
   759       <li>
   760       table-row-group, table-header-group, table-footer-group and table-row offset
   761       relative to its normal position within the table. If table-cells span
   762       multiple rows, only the cells originating in the <a>relative positioned</a> row is
   763       offset.
   765       <li>
   766       table-column-group, table-column do not offset the respective column and has
   767       no visual affect when 'position': ''relative'' is applied.
   769       <li>
   770       table-caption and table-cell offset relative to its normal position within
   771       the table. If a table cell spans multiple columns or rows the full spanned
   772       cell is offset.
   773     </ul>
   775   <dt><dfn>absolute</dfn></dt>
   776   <dd>
   777     The box’s position (and possibly size) is specified with the 'top', 'right',
   778     'bottom', and 'left' properties. These properties specify offsets with respect
   779     to the box’s <a>containing block</a>. Absolutely positioned boxes
   780     are taken out of the normal flow. This means they have no impact on the layout
   781     of later siblings. Though absolutely positioned boxes may have margins, those
   782     margins do not <a href="http://www.w3.org/TR/CSS2/box.html#collapsing-margins">
   783     collapse</a> with any other margins.
   785   <dt><dfn>sticky</dfn></dt>
   786   <dd>
   787     The box’s position is calculated according to the <a>normal flow</a>
   788     (this is called the position in <a>normal flow</a>). Then the box is offset
   789     relative to its flow root and containing block and in all cases, including
   790     table elements, does not affect the position of any following boxes. When a
   791     box B is stickily positioned, the position of the following box is calculated
   792     as though B were not offset. The effect of 'position': ''sticky'' on table
   793     elements is the same as for 'position': ''relative''
   795   <dt><dfn>fixed</dfn></dt>
   796   <dd>
   797     The box’s position is calculated according to the "absolute" model, but
   798     in addition, the box is fixed with respect to some reference. As with the
   799     "absolute" model, the box’s margins do not collapse with any other margins.
   800     In the case of handheld, projection, screen, tty, and tv media types, the box
   801     is fixed with respect to the <a>viewport</a> and does not move when scrolled.
   802     In the case of the print media type, the box is rendered on every page, and
   803     is fixed with respect to the page box, even if the page is seen through a
   804     <a>viewport</a> (in the case of a print-preview, for example). For other media
   805     types, the presentation is undefined. Authors may wish to specify ''fixed''
   806     in a media-dependent way. For instance, an author may want a box to remain at
   807     the top of the <a>viewport</a> on the screen, but not at the top of each printed
   808     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>
   809     rule, as in:
   810     <div class="example">
   811 <pre><code class="css">
   812 @media screen {
   813     h1#first { position: fixed }
   814 }
   815 @media print {
   816     h1#first { position: static }
   817 }
   818 </code></pre>
   819     </div>
   820     User agents must not paginate the content of fixed boxes.
   822     <p class="note">
   823       Note that user agents may print invisible content in other ways. See
   824       <a href="http://www.w3.org/TR/CSS2/page.html#outside-page-box">"Content outside the page box"</a>.
   825     </p>
   826   </dd>
   827 </dl>
   829   In previous versions of CSS user agents may treat position ''fixed'' as ''static''
   830   on the root element. This specification removes that option and it is now required
   831   that newer user agents treat ''fixed'' value on the root element as defined for
   832   all other elements.
   833 <!-- End section: Choosing a positioning scheme: 'position' property -->
   835 <h3 id="box-offsets-trbl">
   836 Box offsets: 'top', 'right', 'bottom', 'left'</h3>
   838   An element is said to be <a>positioned</a> if its 'position' property has a value other than ''static''.
   839   Positioned elements generate positioned boxes, and may be laid out according
   840   to the following four physical properties:
   842   <pre class="propdef">
   843   Name: top
   844   Value: auto | &lt;length> | &lt;percentage>
   845   Initial: auto
   846   Applies to: positioned elements
   847   Inherited: no
   848   Animatable: &lt;length>, &lt;percentage>
   849   Percentages: refer to height of <a>containing block</a>
   850   Media: visual
   851   Computed value: For 'position': ''relative'', see Relative positioning.<br/> For 'position': ''sticky'', see Sticky positioning.<br/> For 'position': ''static'', ''top/auto''.<br/> Otherwise: if specified as a '&lt;length>', the corresponding absolute length; if specified as a '&lt;percentage>', the specified value; otherwise, ''top/auto''.
   852   </pre>
   854   This property specifies how far an absolutely positioned box’s top margin
   855   edge is offset below the top edge of the box’s <a>containing block</a>.
   857   For relatively positioned boxes, the offset is with respect to the top edge of
   858   the box itself (i.e., the box is given a position in the <a>normal flow</a>,
   859   and then offset from that position according to this property).
   861   For stickily positioned boxes, the value is used to compute the <em>sticky-constraint
   862   rectangle</em> as described in Sticky positioning.
   864   For absolutely positioned elements whose <a>containing
   865   block</a> is based on a block-level element, this property is an offset from
   866   the padding edge of that element.
   868   <pre class="propdef">
   869   Name: right
   870   Value: auto | &lt;length> | &lt;percentage>
   871   Initial: auto
   872   Applies to: positioned elements
   873   Inherited: no
   874   Animatable: &lt;length>, &lt;percentage>
   875   Percentages: refer to height of <a>containing block</a>
   876   Media: visual
   877   Computed value: For 'position': ''relative'', see Relative positioning.<br/> For 'position': ''sticky'', see Sticky positioning.<br/> For 'position': ''static'', ''right/auto''.<br/> Otherwise: if specified as a '&lt;length>', the corresponding absolute length; if specified as a '&lt;percentage>', the specified value; otherwise, ''right/auto''.
   878   </pre>
   880   Similar to 'top', but specifies how far a box’s right margin edge is offset
   881   to the left of the right edge of the box’s <a>containing block</a>.
   883   For relatively positioned boxes, the offset is with respect to the right edge
   884   of the box itself (i.e., the box is given a position in the <a>normal flow</a>,
   885   and then offset from that position according to this property).
   887   For stickily positioned boxes, the value is used to compute the <em>sticky-constraint
   888   rectangle</em> as described in Sticky positioning.
   890   For absolutely positioned elements whose <a>containing
   891   block</a> is based on a block-level element, this property is an offset from
   892   the padding edge of that element.
   894   <pre class="propdef">
   895   Name: bottom
   896   Value: auto | &lt;length> | &lt;percentage>
   897   Initial: auto
   898   Applies to: positioned elements
   899   Inherited: no
   900   Animatable: &lt;length>, &lt;percentage>
   901   Percentages: refer to height of <a>containing block</a>
   902   Media: visual
   903   Computed value: For 'position': ''relative'', see Relative positioning.<br/> For 'position': ''sticky'', see Sticky positioning.<br/> For 'position': ''static'', ''bottom/auto''.<br/> Otherwise: if specified as a '&lt;length>', the corresponding absolute length; if specified as a '&lt;percentage>', the specified value; otherwise, ''bottom/auto''.
   904   </pre>
   906   Similar to 'top', but specifies how far a box’s bottom margin edge is offset
   907   above the bottom edge of the box’s <a>containing block</a>.
   909   For relatively positioned boxes, the offset is with respect to the bottom edge
   910   of the box itself (i.e., the box is given a position in the <a>normal flow</a>,
   911   and then offset from that position according to this property).
   913   For stickily positioned boxes, the value is used to compute the <em>sticky-constraint
   914   rectangle</em> as described in Sticky positioning.
   916   For absolutely positioned elements whose <a>containing
   917   block</a> is based on a block-level element, this property is an offset from
   918   the padding edge of that element.
   920   <pre class="propdef">
   921   Name: left
   922   Value: auto | &lt;length> | &lt;percentage>
   923   Initial: auto
   924   Applies to: positioned elements
   925   Inherited: no
   926   Animatable: &lt;length>, &lt;percentage>
   927   Percentages: refer to height of <a>containing block</a>
   928   Media: visual
   929   Computed value: For 'position': ''relative'', see Relative positioning.<br/> For 'position': ''sticky'', see Sticky positioning.<br/> For 'position': ''static'', ''left/auto''. Otherwise: if specified as a '&lt;length>', the corresponding absolute length; if specified as a '&lt;percentage>', the specified value; otherwise, ''left/auto''.
   930   </pre>
   932   Similar to 'top', but specifies how far a box’s left margin edge is offset
   933   to the right of the left edge of the box’s <a>containing block</a>.
   935   For relatively positioned boxes, the offset is with respect to the left edge of
   936   the box itself (i.e., the box is given a position in the <a>normal flow</a>,
   937   and then offset from that position according to this property).
   939   For stickily positioned boxes, the value is used to compute the <em>sticky-constraint
   940   rectangle</em> as described in Sticky positioning.
   942   For absolutely positioned elements whose <a>containing
   943   block</a> is based on a block-level element, this property is an offset from
   944   the padding edge of that element.
   946   The values for the four properties have the following meanings:
   948 <dl dfn-for="top,right,bottom,left, offset-start, offset-end, offset-before, offset-after" dfn-type="value">
   949   <dt><dfn>&lt;length></dfn>
   950   <dd>
   951     The offset is a fixed distance from the reference edge. Negative values are
   952     allowed.
   954   <dt><dfn>&lt;percentage></dfn>
   955   <dd>
   956     The offset is a percentage of the <a>containing block’s</a> width (for 'left' or 'right')
   957     or height (for 'top' and 'bottom').
   958     For stickily positioned elements, the offset is a percentage of the flow root's
   959     width (for 'left' or 'right') or height (for 'top' or 'bottom').
   960     Negative values are allowed.
   962   <dt><dfn>auto</dfn></dt>
   963   <dd>
   964     For non-replaced elements, the effect of this value depends on which of related
   965     properties have the value ''top/auto'' as well. See the sections on the
   966     'width' and 'height' of absolutely positioned, non-replaced elements for details.
   967     For replaced elements, the effect of this value depends only on the intrinsic
   968     dimensions of the replaced content. See the sections on the 'width' and 'height'
   969     of absolutely positioned, replaced elements for details.
   970 </dl>
   972   <p class="note">
   973     Note, for fixed positioned elements using large values or
   974     negative values may easily move elements outside the <a>viewport</a> and make the
   975     contents unreachable through scrolling or other means. Authors should be aware that
   976     fixed position elements are always relative to the <span>initial
   977     containing block</span>.
   978   </p>
   979 <!-- End section: Box offsets: 'top', 'right', 'bottom', 'left'  -->
   981 <h3 id="logical-box-offsets-beaso">
   982 Logical box offsets: 'offset-before', 'offset-end', 'offset-after' and 'offset-start'</h3>
   984   Logical offset properties allow for offseting positioned boxes based on the
   985   'writing-mode' and 'direction' properties. When both the physical property and
   986   equivalent logical property (based on 'writing-mode' and 'direction') are
   987   specified the physical property computes to the computed value of the coresponding
   988   logical property.
   990   Positioned elements generate positioned boxes, and may be laid out according to
   991   the following four logical properties taking into account the 'writing-mode'
   992   and 'direction' of the <a>containing block</a>:
   994   <pre class="propdef">
   995     Name: offset-before, offset-after, offset-start, offset-end
   996     Value: auto | &lt;length> | &lt;percentage>
   997     Initial: auto
   998     Applies to: positioned elements
   999     Inherited: no
  1000     Animatable: &lt;length>, &lt;percentage>
  1001     Percentages: refer to height of <a>containing block</a>
  1002     Media: visual
  1003     Computed value: For ''position: relative'', see Relative positioning.<br/> For ''position: sticky'', see Sticky positioning.<br/> For ''position: static'', ''top/auto''.<br/> Otherwise: if specified as a <<length>>, the corresponding absolute length; if specified as a <<percentage>>, the specified value; otherwise, ''top/auto''.
  1004   </pre>
  1006   For an absolutely positioned box this property specifies how far the coresponding
  1007   margin edge is offset from the coresponding physical reference edge of the box’s
  1008   <a>containing block</a>.
  1010   The partiucular physical reference edge that is used when offsetting is based
  1011   on the 'writing-mode' and 'direction' properties.
  1013   The combination of the 'writing-mode' and 'direction' properties determine the
  1014   appropriate physical reference edge for offsetting.
  1016   The table below shows logical offset properties (per 'writing-mode' and
  1017   'direction') and the physical reference edge from which the offset will occur.
  1019   <div class="figure">
  1020     <table id="logical-physical-relations" class="lpr">
  1021       <thead>
  1022         <tr>
  1023           <th colspan="2" rowspan="2"></th>
  1024           <td colspan="6">'writing-mode' / 'direction'</td>
  1025         </tr>
  1026         <tr>
  1027           <td>horizontal-tb / ltr</td>
  1028           <td>horizontal-tb / rtl</td>
  1029           <td>vertical-rl / ltr</td>
  1030           <td>vertical-rl / rtl</td>
  1031           <td>vertical-lr / ltr</td>
  1032           <td>vertical-lr / rtl</td>
  1033         </tr>
  1034       </thead>
  1035       <tbody>
  1036         <tr>
  1037           <td rowspan="4"><div>Edge</div></td>
  1038           <td>top</td>
  1039           <td>offset-before</td>
  1040           <td>offset-before</td>
  1041           <td>offset-start</td>
  1042           <td>offset-end</td>
  1043           <td>offset-start</td>
  1044           <td>offset-end</td>
  1045         </tr>
  1046         <tr>
  1047           <td>right</td>
  1048           <td>offset-end</td>
  1049           <td>offset-start</td>
  1050           <td>offset-before</td>
  1051           <td>offset-before</td>
  1052           <td>offset-after</td>
  1053           <td>offset-after</td>
  1054         </tr>
  1055         <tr>
  1056           <td>bottom</td>
  1057           <td>offset-after</td>
  1058           <td>offset-after</td>
  1059           <td>offset-end</td>
  1060           <td>offset-start</td>
  1061           <td>offset-end</td>
  1062           <td>offset-start</td>
  1063         </tr>
  1064         <tr>
  1065           <td>left</td>
  1066           <td>offset-start</td>
  1067           <td>offset-end</td>
  1068           <td>offset-after</td>
  1069           <td>offset-after</td>
  1070           <td>offset-before</td>
  1071           <td>offset-before</td>
  1072         </tr>
  1073       </tbody>
  1074     </table>
  1075     <p class="caption">
  1076       Relationship of physical offset edges and the logical properties per
  1077       'writing-mode' and 'direction'.
  1078     </p>
  1079   </div>
  1081   <p class="issue">The logical property definitions should move to the Logical Properties module.</p>
  1083   For relatively positioned boxes, the offset is with respect to the property’s
  1084   coresponding physical reference edge of the box itself (i.e., the box is given a
  1085   position in the <a>normal flow</a>, and then offset from that position according
  1086   to the property).
  1088   <p class="issue">This needs to be defined for sticky positioning.</p>
  1090   For absolutely positioned elements whose <a>containing block</a>
  1091   is based on a block-level element, this property is an offset from the coresponding
  1092   padding edge of that element.
  1094   <p class="note">
  1095     Note, for fixed positioned elements using large values or
  1096     negative values may easily move elements outside the <a>viewport</a> and make the
  1097     contents unreachable through scrolling or other means. Authors should be aware that
  1098     fixed position elements are always relative to the <span>initial
  1099     containing block</span>.
  1100   </p>
  1102 <h2 id="position-root">
  1103 Choosing a different containing block for positioning</h2>
  1105 <h3 id="attachment-properties">
  1106 Attachment properties: 'attachment-type', 'attachment-top', 'attachment-right', 'attachment-bottom', 'attachment-left', and 'attachment'</h3>
  1107 <!--
  1108 <h3 id="position-root">Choosing a different containing block for positioning: 'position-reference' property</h3>
  1110 The 'position-reference' property determines what element to use as a containing block for the current element.
  1112 <pre class='propdef'>
  1113 Name: position-reference
  1114 Value: auto | parent(<<number>>) | container | root | page | viewprot | element()
  1115 Initial: auto
  1116 Applies to: positioned elements
  1117 Inherited: no
  1118 Animatable: no
  1119 Percentages: n/a
  1120 Media: visual
  1121 Computed value: specified value, but see prose
  1122 </pre>
  1124 The values of this property have the following meanings:
  1126 <dl dfn-type=value dfn-for=position-reference>
  1127     <dt><dfn>auto</dfn></dt>
  1128     <dd>
  1130     </dd>
  1131     <dt><dfn>parent(<<number>>)</dfn></dt>
  1132     <dd>
  1133         Use the parent element as the <a>containing block</a> for the positioned element.
  1135         Issue: What's the <<number>> for???
  1136     </dd>
  1137     <dt><dfn>container</dfn></dt>
  1138     <dd>
  1139         Use the container as the <span>containing box</span>.<br>
  1140         In the case of multi-column layout the individual column defines the containing
  1141         block even though the individual column is not an actual element "block box". If
  1142         not inside a multi-column element then this value computes to ''position-reference/auto''.
  1143     </dd>
  1144     <dt><dfn>root</dfn></dt>
  1145     <dd>
  1146         Use the root element (for HTML and XHTML the html element) as the <a>containing block</a> for the positioned element.
  1147     </dd>
  1148     <dt><dfn>nth-parent()</dfn></dt>
  1149     <dd>
  1151         <p class="issue">
  1152             Inserting and removing elements from the tree may cause odd behavior with
  1153             'nth-parent()'. Is this really a good concept?
  1154     </dd>
  1155     <dt><dfn>element()</dfn></dt>
  1156     <dd>
  1158         <p class="issue">
  1159             Inserting and removing elements from the tree may cause odd behavior with
  1160             'element()'. Is this really a good concept?
  1161         </p>
  1162     </dd>
  1163 </dl>
  1164 -->
  1165   <p class="issue">
  1166     Ideas have been raised to allow changing the positioning containing block or
  1167     allowing positioning and sizing to use different containing blocks.
  1168   </p>
  1169 <!-- End section: Choosing a different containing block for positioning: 'position-reference' property -->
  1171 <h2 id="size-and-position-details">
  1172 Sizing and positioning details</h2>
  1174 <h3 id="abs-non-replaced-width">
  1175 The width of absolute or fixed positioned, non-replaced elements</h3>
  1177   The constraint that determines the used values for these elements is:
  1179   <code>
  1180     'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width' +
  1181     'padding-right' + 'border-right-width' + 'margin-right' +
  1182     'right' = width of containing block
  1183  </code>
  1185   If all three of 'left', 'width', and 'right' are ''left/auto'': First set any ''margin/auto'' values
  1186   for 'margin-left' and 'margin-right' to ''0''. Then, if the 'direction' property of the
  1187   element establishing the static-position <a>containing block</a> is ''ltr'' set
  1188   'left' to the static position and apply rule number <em>three</em> below; otherwise, set
  1189   'right' to the static-position and apply rule number <em>one</em> below.
  1191   If none of the three is ''left/auto'': If both 'margin-left' and 'margin-right' are ''margin/auto'',
  1192   solve the equation under the extra constraint that the two margins get equal values,
  1193   unless this would make them negative, in which case when direction of the containing
  1194   block is ''ltr'' (''rtl''), set 'margin-left' ('margin-right') to ''0'' and solve for
  1195   'margin-right' ('margin-left'). If one of 'margin-left' or 'margin-right' is ''margin/auto'',
  1196   solve the equation for that value. If the values are over-constrained, ignore the value
  1197   for 'left' (in case the 'direction' property of the <a>containing block</a> is
  1198   ''rtl'') or 'right' (in case 'direction' is ''ltr'') and solve for that value.
  1200   Otherwise, set ''margin/auto'' values for 'margin-left' and 'margin-right' to ''0'', and pick
  1201   one of the following six rules that apply.
  1203   <ol>
  1204     <li>
  1205     If 'left' and 'width' are ''left/auto'' and 'right' is not ''right/auto'', then the width is
  1206     shrink-to-fit. Then solve for 'left'.
  1208     <li>
  1209     If 'left' and 'right' are ''left/auto'' and 'width' is not ''width/auto'', then if the
  1210     'direction' property of the element establishing the static-position
  1211     <a>containing block</a> is ''ltr'' set 'left' to the static-position,
  1212     otherwise set 'right' to the static-position. Then solve for 'left' (if 'direction
  1213     is ''rtl'') or 'right' (if 'direction' is ''ltr'').
  1215     <li>
  1216     If 'width' and 'right' are ''width/auto'' and 'left' is not ''left/auto'', then the width is
  1217     shrink-to-fit. Then solve for 'right'.
  1219     <li>
  1220     If 'left' is ''left/auto'', 'width' and 'right' are not ''width/auto'', then solve for 'left'.
  1222     <li>
  1223     If 'width' is ''width/auto'', 'left' and 'right' are not ''left/auto'', then solve for 'width'.
  1225     <li>
  1226     If 'right' is ''right/auto'', 'left' and 'width' are not ''left/auto'', then solve for 'right'.
  1227   </ol>
  1229 <table class=data id='abspos-auto'>
  1230   <style scoped>
  1231   #abspos-auto ul { list-style-type: none; margin: 0; }
  1232   #abspos-auto caption { caption-side: bottom; }
  1233   </style>
  1234   <caption>
  1235     Summary of rules for <code>dir=ltr</code> in horizontal writing modes
  1236   </caption>
  1237   <colgroup span=5></colgroup>
  1238   <colgroup span=1></colgroup>
  1239   <thead>
  1240     <tr>
  1241       <th colspan=5>Is auto?
  1242       <th rowspan=2>Result
  1243     <tr>
  1244       <th>'left'
  1245       <th>'width'
  1246       <th>'right'
  1247       <th>'margin-left'
  1248       <th>'margin-right'
  1249   <tbody>
  1250     <tr>
  1251       <td>✔
  1252       <td>✔
  1253       <td>✔
  1254       <td colspan=2>any
  1255       <td>
  1256         <ul>
  1257           <li>auto margins → zero
  1258           <li>left → static pos
  1259           <li>width → shrink-to-fit
  1260           <li>right → solve
  1261         </ul>
  1262     <tr>
  1263       <td rowspan=4>✘
  1264       <td rowspan=4>✘
  1265       <td rowspan=4>✘
  1266       <td>✔
  1267       <td>✘
  1268       <td rowspan=2>
  1269         auto margin → free space
  1270     <tr>
  1271       <td>✘
  1272       <td>✔
  1273     <tr>
  1274       <td>✔
  1275       <td>✔
  1276       <td>
  1277         <ul>
  1278           <li>margins split positive free space
  1279           <li>right margin gets negative free space
  1280         </ul>
  1281     <tr>
  1282       <td>✘
  1283       <td>✘
  1284       <td>
  1285         treat 'right' as ''right/auto''
  1286     <tr>
  1287       <td>✔
  1288       <td>✘
  1289       <td>✔
  1290       <td colspan=2>any
  1291       <td>
  1292         <ul>
  1293           <li>auto margins → zero
  1294           <li>left → static pos
  1295           <li>width → as specified
  1296           <li>right → solve
  1297         </ul>
  1298     <tr>
  1299       <td>✔
  1300       <td>✔
  1301       <td>✘
  1302       <td colspan=2>any
  1303       <td>
  1304         <ul>
  1305           <li>auto margins → zero
  1306           <li>left → solve
  1307           <li>width → shrink-to-fit
  1308           <li>right → as specified
  1309         </ul>
  1310     <tr>
  1311       <td>✘
  1312       <td>✔
  1313       <td>✔
  1314       <td colspan=2>any
  1315       <td>
  1316         <ul>
  1317           <li>auto margins → zero
  1318           <li>left → as specified
  1319           <li>width → shrink-to-fit
  1320           <li>right → solve
  1321         </ul>
  1322     <tr>
  1323       <td>✔
  1324       <td>✘
  1325       <td>✘
  1326       <td colspan=2 rowspan=3>any
  1327       <td rowspan=3>
  1328         <ul>
  1329           <li>auto margins → zero
  1330           <li>solve for auto
  1331         </ul>
  1332     <tr>
  1333       <td>✘
  1334       <td>✘
  1335       <td>✔
  1336     <tr>
  1337       <td>✘
  1338       <td>✔
  1339       <td>✘
  1340 </table>
  1342 <!-- End section: The width of absolute or fixed positioned, non-replaced element -->
  1344 <h3 id="abs-replaced-width">
  1345 The width of absolute or fixed positioned, replaced elements</h3>
  1347   If 'height' and 'width' both have computed values of <css>auto</css> and the element also has an
  1348   intrinsic width, then that intrinsic width is the used value of 'width'.
  1350   If 'height' and 'width' both have computed values of <css>auto</css> and the element has no
  1351   intrinsic width, but does have an intrinsic height and intrinsic ratio; or if 'width'
  1352   has a computed value of <css>auto</css>, 'height' has some other computed value, and the element
  1353   does have an intrinsic ratio; then the used value of 'width' is:
  1355   <code>(used height) * (intrinsic ratio)</code>
  1357   If 'height' and 'width' both have computed values of <css>auto</css>, the element has an
  1358   intrinsic ratio but no intrinsic height or width, and the <a>containing block’s</a> width does
  1359   not itself depend on the replaced element’s width, then the used value of 'width' is
  1360   calculated from the constraint equation used for
  1361   <a href="http://www.w3.org/TR/CSS21/visudet.html#blockwidth">block-level, non-replaced elements in <a>normal flow</a></a>.
  1363   Otherwise, if 'width' has a computed value of <css>auto</css>, and the element has an intrinsic
  1364   width, then that intrinsic width is the used value of 'width'.
  1366   Otherwise, if 'width' has a computed value of <css>auto</css>, but none of the conditions above
  1367   are met, and then the used value of 'width' becomes ''300px''. If ''300px'' is too wide
  1368   to fit the device, user agents should use the width of the largest rectangle that has a
  1369   2:1 ratio and fits the device instead.
  1371   After establishing the 'width', in order to position the replaced element, apply the
  1372   following rules as appropriate.
  1374   <ol>
  1375     <li>
  1376     If both 'left' and 'right' have the value <css>auto</css>, and if the 'direction' property
  1377     of the element establishing the static-position <a>containing block</a> is
  1378     ''ltr'', set 'left' to the static position and solve for 'right'; else if
  1379     'direction' is ''rtl'', set 'right' to the static position and solve for 'left'.
  1381     <li>
  1382     If 'left' is <css>auto</css> and 'right' is not <css>auto</css>, replace any <css>auto</css> on
  1383     'margin-left' or 'margin-right' with ''0'', then solve for 'left'.
  1385     <li>
  1386     If 'right' is <css>auto</css> and 'left' is not <css>auto</css>, replace any <css>auto</css> on
  1387     'margin-left' or 'margin-right' with ''0'', then solve for 'right'.
  1389     <li>
  1390     If at this point both 'margin-left' and 'margin-right' are still <css>auto</css>, solve the
  1391     equation under the extra constraint that the two margins must get equal values,
  1392     unless this would make them negative, in which case when the direction of the
  1393     <a>containing block</a> is ''ltr'' (''rtl''), set 'margin-left'
  1394     ('margin-right') to ''0'' and solve for 'margin-right' ('margin-left').
  1396     <li>
  1397     If at this point there is an <css>auto</css> remaining, solve the equation for that value.
  1399     <li>
  1400     If at this point the values are over-constrained, ignore the value for either 'left'
  1401     (in case the 'direction' property of the <a>containing block</a> is ''rtl'')
  1402     or 'right' (in case 'direction' is ''ltr'') and solve for that value.
  1403   </ol>
  1404 <!-- End section: The width of absolute or fixed positioned, replaced element -->
  1406 <h3 id="abs-non-replaced-height">
  1407 The height of absolute or fixed positioned, non-replaced elements</h3>
  1409   For absolutely positioned elements, the used values of the vertical dimensions must
  1410   satisfy this constraint:
  1412   <code>
  1413     'top' + <span>'margin-top'</span> + <span>'border-top-width'</span> + <span>'padding-top'</span> + 'height' +
  1414     <span>'padding-bottom'</span> + <span>'border-bottom-width'</span> + <span>'margin-bottom'</span> + 'bottom'
  1415     = <span>height of containing block</span>
  1416   </code>
  1418   If all three of 'top', 'height', and 'bottom' are <css>auto</css>: First set any <css>auto</css>
  1419   values for 'margin-top' and 'margin-bottom' to ''0'', then set 'top' to the static
  1420   position, and finally apply rule number <em>three</em> below.
  1422   If none of the three are <css>auto</css>: If both 'margin-top' and 'margin-bottom' are <css>auto</css>,
  1423   solve the equation under the extra constraint that the two margins get equal values. If
  1424   one of 'margin-top' or 'margin-bottom' is <css>auto</css>, solve the equation for that value. If
  1425   the values are over-constrained, ignore the value for 'bottom' and solve for that value.
  1427   Otherwise, set <css>auto</css> values for 'margin-top' and 'margin-bottom' to ''0'', and pick
  1428   one of the following six rules that apply.
  1430   <ol>
  1431     <li>
  1432     If 'top' and 'height' are <css>auto</css> and 'bottom' is not <css>auto</css>, then the height is
  1433     based on the <a href="#root-height">Auto heights for block formatting context
  1434     roots</a>, and solve for 'top'.
  1436     <li>
  1437     If 'top' and 'bottom' are <css>auto</css> and 'height' is not <css>auto</css>, then set 'top' to
  1438     the static position, then solve for 'bottom'.
  1440     <li>
  1441     If 'height' and 'bottom' are <css>auto</css> and 'top' is not <css>auto</css>, then the height is
  1442     based on the <a href="#root-height">Auto heights for block formatting context
  1443     roots</a>, and solve for 'bottom'.
  1445     <li>
  1446     If 'top' is <css>auto</css>, 'height' and 'bottom' are not <css>auto</css>, then solve for 'top'.
  1448     <li>
  1449     If 'height' is <css>auto</css>, 'top' and 'bottom' are not <css>auto</css>, then solve for 'height'.
  1451     <li>
  1452     If 'bottom' is <css>auto</css>, 'top' and 'height' are not <css>auto</css>, then solve for 'bottom'.
  1453   </ol>
  1454 <!-- End section: The height of absolute or fixed positioned, non-replaced element -->
  1456 <h3 id="abs-replaced-height">
  1457 The height of absolute or fixed positioned, replaced elements</h3>
  1459   If 'height' and 'width' both have computed values of <css>auto</css> and the element also has an
  1460   intrinsic height, then that intrinsic height is the used value of 'height'.
  1462   Otherwise, if 'height' has a computed value of <css>auto</css> and the element has an intrinsic
  1463   ratio then the used value of 'height' is:
  1465   <code>(used width) / (intrinsic ratio)</code></p>
  1467   Otherwise, if 'height' has a computed value of <css>auto</css> and the element has an intrinsic
  1468   height, then that intrinsic height is the used value of 'height'.
  1470   Otherwise, if 'height' has a computed value of <css>auto</css>, but none of the conditions above
  1471   are met, then the used value of 'height' must be set to the height of the largest
  1472   rectangle that has a 2:1 ratio, has a height not greater than ''150px'', and has a width not
  1473   greater than the device width.
  1475   After establishing the 'height', in order to position the replaced element, apply the
  1476   following rules as appropriate.
  1478   <ol>
  1479     <li>
  1480     If both 'top' and 'bottom' have the value <css>auto</css>, replace 'top' with the
  1481     element’s static position.
  1483     <li>
  1484     If 'bottom' is <css>auto</css>, replace any <css>auto</css> on 'margin-top' or 'margin-bottom'
  1485     with ''0''.
  1487     <li>
  1488     If at this point both 'margin-top' and 'margin-bottom' are still <css>auto</css>,
  1489     solve the equation under the extra constraint that the two margins must get
  1490     equal values.
  1492     <li>
  1493     If at this point there is only one <css>auto</css> remaining, solve the equation
  1494     for that value.
  1496     <li>
  1497     If at this point the values are over-constrained, ignore the value for 'bottom'
  1498     and solve for that value.
  1499   </ol>
  1500 <!-- End section: The height of absolute or fixed positioned, replaced element -->
  1502 <h3 id="root-height">
  1503 Auto heights for block formatting context roots</h3>
  1505   In certain cases (see, e.g., <a href="#abs-non-replaced-height">The height of
  1506   absolute or fixed positioned, non-replaced element</a> above), the height
  1507   of an element that establishes a block formatting context is computed as follows:
  1509   If it only has inline-level children, the height is the distance between the
  1510   top of the topmost line box and the bottom of the bottommost line box.
  1512   If it has block-level children, the height is the distance between the top
  1513   margin-edge of the topmost block-level child box and the bottom margin-edge of
  1514   the bottommost block-level child box.
  1516   Absolutely positioned children are ignored, and relatively positioned boxes are
  1517   considered without their offset. Note that the child box may be an <a href="http://www.w3.org/TR/CSS2/visuren.html#anonymous-block-level">anonymous block box</a>.
  1519   In addition, if the element has any floating descendants whose bottom margin edge
  1520   is below the element’s bottom content edge, then the height is increased to
  1521   include those edges. Only non-positioned <a>floats</a> that
  1522   participate in this block formatting context are taken into account, e.g.,
  1523   <a>floats</a> inside absolutely positioned descendants or
  1524   other <a>floats</a> are not.
  1525 <!-- End section: Auto heights for block formatting context roots -->
  1526 <!-- End section: Sizing and positioning details -->
  1528 <h2 id="dis-pos-flo">
  1529 Relationships between 'display', 'position', and 'float'</h2>
  1531   The three properties that affect box generation and layout &mdash; 'display',
  1532   'position', and 'float' &mdash; interact as follows:
  1534   <ol>
  1535     <li>
  1536     If 'display' has the value ''display/none'', then 'position' and 'float' do not apply.
  1537     In this case, the element generates no box.
  1539     <li>
  1540     Otherwise, if 'position' has the value ''absolute'' or ''fixed'',
  1541     and the value of 'float' is ''float/left'' or ''float/right'', the box is absolutely
  1542     positioned and the computed value of 'float' is ''float/none''. The 'display' is
  1543     set according to the table below. Positioning of the box will determined by
  1544     the 'top', 'right', 'bottom' and 'left' properties and the box’s
  1545     <a>containing block</a>.
  1547     <li>
  1548     Otherwise, if 'float' is other than ''float/none'', the box is <a>floated</a> and 'display' is set according to the table below.
  1550     <li>
  1551     Otherwise, if the element is the root element, 'display' is set according to the
  1552     table below.
  1554     <li>
  1555     Otherwise, the remaining 'display' property values apply as specified.
  1556   </ol>
  1558   <table class="relationship-table">
  1559     <tr>
  1560       <th>Specified value</th>
  1561       <th>Computed value</th>
  1562     </tr>
  1563     <tr>
  1564       <td>inline-table</td>
  1565       <td>table</td>
  1566     </tr>
  1567     <tr>
  1568       <td>
  1569         inline, <span>table-row-group</span>, <span>table-column</span>,
  1570         <span>table-column-group</span>,
  1571         <span>table-header-group</span>, <span>table-footer-group</span>,
  1572         <span>table-row</span>,
  1573         <span>table-cell</span>, <span>table-caption</span>, <span>inline-block</span>
  1574       </td>
  1575       <td>block</td>
  1576     </tr>
  1577     <tr>
  1578       <td>others </td>
  1579       <td><span>same as specified</span></td>
  1580     </tr>
  1581   </table>
  1583   <p class="note">
  1584     For new values defined for the 'display' property, the respective modules that define a
  1585     new value also define the handling of the relationship with positioning and floats.
  1586   </p>
  1587 <!-- End section: Relationships between 'display', 'position', and 'float' -->
  1589 <h2 id="comparison">
  1590 Comparison of normal flow, floats, and positioning</h2>
  1592   <em>This section is not normative.</em>
  1594   To illustrate the differences between <a>normal flow</a>,
  1595   <a>relative positioning</a>, <a>floats</a>,
  1596   and absolute positioning, we provide a series of examples based on the following HTML:
  1598   <div class="example">
  1599     <pre class="lang-html">
  1600     &lt;!DOCTYPE html>
  1601     &lt;html>
  1602         &lt;head>
  1603             &lt;title>Comparison of positioning schemes&lt;/title>
  1604             &lt;style>
  1605               body { display: block; font-size:12px; line-height: 200%;
  1606                       width: 400px; height: 400px }
  1607               p    { display: block }
  1608               span { display: inline }
  1609             &lt;/style>
  1610         &lt;/head>
  1611         &lt;body>
  1612         &lt;p>
  1613             Beginning of p contents.
  1614             &lt;span id="outer"> Start of outer contents.
  1615             &lt;span id="inner"> Inner contents.&lt;/span>
  1616             End of outer contents.&lt;/span>
  1617             End of p contents.
  1618         &lt;/p>
  1619         &lt;/body>
  1620     &lt;/html>
  1621     </pre>
  1622   </div>
  1624   The final positions of boxes generated by the <em>outer</em> and <em>inner</em>
  1625   elements vary in each example. In each illustration, the numbers to the left of
  1626   the illustration indicate the <a>normal flow</a> position of the
  1627   double-spaced (for clarity) lines.
  1629   Note: The diagrams in this section are illustrative and not to scale. They are
  1630   meant to highlight the differences between the various <a>positioning
  1631   schemes</a>, and are not intended to be reference renderings of the
  1632   examples given.
  1634 <h3 id="comp-normal-flow">
  1635 Normal flow</h3>
  1637   Consider the following CSS declarations for <em>outer</em> and <em>inner</em>
  1638   that do not alter the <a>normal flow</a> of boxes:
  1640   <div class="example">
  1641     <pre class="lang-css">
  1642       #outer { color: red }
  1643       #inner { color: blue }
  1644     </pre>
  1645   </div>
  1647   The P element contains all inline content: <a href="http://www.w3.org/TR/CSS2/visuren.html#anonymous">anonymous inline text</a> and
  1648   two SPAN elements. Therefore, all of the content will be laid out in an inline
  1649   formatting context, within a <a>containing block</a> established by the P element, producing
  1650   something like:
  1652 <figure>
  1653   <img src="images/flow-generic.png" alt="Image illustrating the normal flow of text between parent and sibling boxes.">
  1654   <figcaption>
  1655     All of the text within the P's containing block flows together as continuous text,
  1656     even though it's located in separated nested elements.
  1657   </figcaption>
  1658 </figure>
  1659 <!-- End section: Normal flow -->
  1661 <h3 id="comp-relpos">
  1662 Relative positioning</h3>
  1664   To see the effect of <a>relative positioning</a>,
  1665   we specify:
  1667   <div class="example">
  1668     <pre class="lang-css">
  1669     #outer { position: relative; top: -12px; color: red }
  1670     #inner { position: relative; top: 12px; color: blue }
  1671     </pre>
  1672   </div>
  1674   Text flows normally up to the <em>outer</em> element. The <em>outer</em> text is
  1675   then flowed into its <a>normal flow</a> position and dimensions at the end of line 1. Then,
  1676   the inline boxes containing the text (distributed over three lines) are shifted as a
  1677   unit by ''-12px'' (upwards).
  1679   The contents of <em>inner</em>, as a child of <em>outer</em>, would normally flow
  1680   immediately after the words "of outer contents" (on line 1.5). However, the <em>inner</em>
  1681   contents are themselves offset relative to the <em>outer</em> contents by ''12px''
  1682   (downwards), back to their original position on line 2.
  1684   <p class="note">
  1685     Note that the content following <em>outer</em> is not affected by the relative
  1686     positioning of <em>outer</em>.
  1687   </p>
  1689   <figure>
  1690     <img src="images/flow-relative.png">
  1691     <figcaption>
  1692       The result is identical to normal flow,
  1693       except that the "outer" text is shifted 12px upward,
  1694       without affecting the flow of the "body" or "inner" text.
  1695     </figcaption>
  1696   </figure>
  1698   <p class="note">
  1699     Note also that had the offset of <em>outer</em> been ''-24px'', the text  of <em>outer</em>
  1700     and the body text would have overlapped.
  1701   </p>
  1703 <h3 id="comp-floating">
  1704 Floating a box</h3>
  1706   Now consider the effect of <a href="http://www.w3.org/TR/CSS2/visuren.html#floats">
  1707   floating</a> the <em>inner</em> element’s text to the right by means of the
  1708   following rules:
  1710   <div class="example">
  1711     <pre class="lang-css">
  1712     #outer { color: red }
  1713     #inner { float: right; width: 130px; color: blue }
  1714     </pre>
  1715   </div>
  1717   Text flows normally up to the <em>inner</em> box, which is pulled out of the flow
  1718   and <a>floated</a> to the right margin (its 'width' has been
  1719   assigned explicitly). Line boxes to the left of the float are shortened, and the
  1720   document’s remaining text flows into them.
  1722 <figure>
  1723   <img src="images/flow-float.png" alt="Image illustrating the effects of floating a box.">
  1724   <figcaption>
  1725     The "inner" text lays out in an independent box on the right,
  1726     causing the remaining "body" and "outer" text to flow around it.
  1727   </figcaption>
  1728 </figure>
  1730   To show the effect of the 'clear' property, we add a <em>sibling</em> element to the
  1731   example:
  1733   <div class="example">
  1734     <pre class="lang-html">
  1735     &lt;!DOCTYPE html>
  1736     &lt;html>
  1737         &lt;head>
  1738             &lt;title>Comparison of positioning schemes II&lt;/title>
  1739             &lt;style>
  1740               #inner { float: right; width: 130px; color: blue }
  1741               #sibling { color: red }
  1742             &lt;/style>
  1743         &lt;/head>
  1744         &lt;body>
  1745         &lt;p>
  1746             Beginning of p contents.
  1747             &lt;span id="outer"> Start of outer contents.
  1748             &lt;span id="inner"> Inner contents.&lt;/span>
  1749             &lt;span id="sibling"> Sibling contents.&lt;/span>
  1750             End of outer contents.&lt;/span>
  1751             End of p contents.
  1752         &lt;/p>
  1753         &lt;/body>
  1754     &lt;/html>
  1755     </pre>
  1756   </div>
  1758   These styles cause the <em>inner</em> box to float to the right, as before,
  1759   and the document’s remaining text to flow into the vacated space:
  1761   <figure>
  1762     <img src="images/flow-clear.png" alt="Image illustrating the effects of floating a box without setting the clear property to control the flow of text around the box.">
  1763     <figcaption>
  1764       Identical to the previous example,
  1765       save that there is now "sibling" text
  1766       flowing with the "body" and "outer" text.
  1767     </figcaption>
  1768   </figure>
  1770   However, if the 'clear' property on the <em>sibling</em> element is set to 'right'
  1771   (i.e., the generated <em>sibling</em> box will not accept a position next to
  1772   <a>floating</a> boxes to its right), the <em>sibling</em> content begins to flow below the
  1773   float:
  1775   <div class="example">
  1776     <pre class="lang-css">
  1777     #inner { float: right; width: 130px; color: blue }
  1778     #sibling { clear: right; color: red }
  1779     </pre>
  1780   </div>
  1782   <figure>
  1783     <img src="images/flow-clear2.png" alt="Image illustrating the effects of floating an element with setting the clear property to control the flow of text around the element.">
  1784     <figcaption>
  1785       Now the "sibling" text moves down to below the "inner" text’s box,
  1786       leaving blank space behind.
  1787       The text following the "sibling" text flows after it as normal.
  1788     </figcaption>
  1789   </figure>
  1791 <h3 id="comp-abspos">
  1792 Absolute positioning</h3>
  1794   Next, we consider the effect of absolute positioning. Consider the following CSS
  1795   declarations for <em>outer</em> and <em>inner</em>:
  1797   <div class="example">
  1798     <pre class="lang-css">
  1799     #outer {
  1800         position: absolute;
  1801         top: 200px; left: 200px;
  1802         width: 200px;
  1803         color: red;
  1805     #inner { color: blue }
  1806     </pre>
  1807   </div>
  1809   which cause the top of the <em>outer</em> box to be positioned with respect to its
  1810   <a>containing block</a>. The <a>containing block</a> for a positioned box is established by the
  1811   nearest positioned ancestor (or, if none exists, the <span>initial containing block</span>, as in
  1812   our example). The top side of the <em>outer</em> box is ''200px'' below the top of the
  1813   <a>containing block</a> and the left side is ''200px'' from the left side. The child box of
  1814   <em>outer</em> is flowed normally with respect to its parent.
  1816   <figure>
  1817     <img src="images/flow-absolute.png" alt="Image illustrating the effects of absolutely positioning a box.">
  1818     <figcaption>
  1819       All of the text within #outer (the "outer" and "inner" text)
  1820       moves down to an independent box in the lower right corner.
  1821       The two halves of "body" text flow together.
  1822     </figcaption>
  1823   </figure>
  1825   The following example shows an absolutely positioned box that is a child of a relatively
  1826   positioned box. Although the parent <em>outer</em> box is not actually offset, setting
  1827   its 'position' property to ''position/relative'' means that its box may serve as the containing
  1828   block for positioned descendants. Since the <em>outer</em> box is an inline box that is
  1829   split across several lines, the first inline box’s top and left edges (depicted by thick
  1830   dashed lines in the illustration below) serve as references for 'top' and 'left' offsets.
  1832   <div class="example">
  1833     <pre class="lang-css">
  1834     #outer {
  1835         position: relative;
  1836         color: red
  1838     #inner {
  1839         position: absolute;
  1840         top: 200px; left: -100px;
  1841         height: 130px; width: 130px;
  1842         color: blue;
  1844     </pre>
  1845   </div>
  1847   This results in something like the following:
  1849   <figure>
  1850     <img src="images/flow-abs-rel.png" alt="Image illustrating the effects of absolutely positioning a box with respect to a containing block.">
  1851     <figcaption>
  1852       The "inner" text is positioned in an independent box,
  1853       relative to the top-left corner of the start of the "outer" text.
  1854     </figcaption>
  1855   </figure>
  1857   If we do not position the <em>outer</em> box:
  1859   <div class="example">
  1860     <pre class="lang-css">
  1861     #outer { color: red }
  1862     #inner {
  1863         position: absolute;
  1864         top: 200px; left: -100px;
  1865         height: 130px; width: 130px;
  1866         color: blue;
  1868     </pre>
  1869   </div>
  1871   the <a>containing block</a> for <em>inner</em> becomes the <span>initial
  1872   containing block</span> (in our example). The following illustration shows where
  1873   the <em>inner</em> box would end up in this case.
  1875   <figure>
  1876     <img src="images/flow-static.png" alt="Image illustrating the effects of absolutely positioning a box with respect to a containing block established by a normally positioned parent.">
  1877     <figcaption>
  1878       Same as before,
  1879       except now the "inner text" is positioned relative to the top-left corner of the page itself.
  1880     </figcaption>
  1881   </figure>
  1883   Relative and absolute positioning may be used to implement change bars, as shown
  1884   in the following example. The following fragment:
  1886   <div class="example">
  1887     <pre class="lang-html">
  1888     &lt;p style="position: relative; margin-right: 10px; left: 10px;">
  1889       I used two red hyphens to serve as a change bar. They
  1890       will "float" to the left of the line containing THIS
  1891       &lt;span style="position: absolute; top: auto; left: -1em; color: red;">--&lt;/span>
  1892       word.
  1893     &lt;/p>
  1894     </pre>
  1895   </div>
  1897   might result in something like:
  1899   <figure>
  1900     <img src="images/changebar.png" alt="Image illustrating the use of floats to create a changebar effect.">
  1901     <figcaption>
  1902       The two red hyphens, indicating a change,
  1903       sit in the left margin of the page
  1904       on the line containing the word "THIS",
  1905       regardless of what line that ends up being.
  1906     </figcaption>
  1907   </figure>
  1909   First, the paragraph (whose <a>containing block</a> sides are shown in the
  1910   illustration) is flowed normally. Then it is offset ''10px'' from the left edge
  1911   of the <a>containing block</a> (thus, a right margin of ''10px'' has been
  1912   reserved in anticipation of the offset). The two hyphens acting as change bars
  1913   are taken out of the flow and positioned at the current line (due to 'top: auto'),
  1914   ''-1em'' from the left edge of its containing block (established by the P in
  1915   its final position).  The result is that the change bars seem to "float" to the
  1916   left of the current line.
  1918 <h2 id="layered-presentation">
  1919 Layered presentation</h2>
  1921   <em>In the following sections, the expression "in front of" means closer to the
  1922   user as the user faces the screen.</em>
  1924   In CSS, each box has a position in three dimensions. In addition to their horizontal
  1925   and vertical positions, boxes lie along a "z-axis" and are formatted one on top
  1926   of the other. Z-axis positions are particularly relevant when boxes overlap
  1927   visually. This section discusses how boxes may be positioned along the z-axis.
  1929   Each box belongs to one <dfn export>stacking context</dfn>. Each box in a given stacking
  1930   context has an integer <dfn export>stack level</dfn>, which is its position on the z-axis
  1931   relative to other boxes in the same stacking context. Boxes with greater stack
  1932   levels are always formatted in front of boxes with lower stack levels. Boxes may
  1933   have negative stack levels. Boxes with the same stack level in a stacking context
  1934   are stacked bottom-to-top according to document tree order.
  1936   The root element creates a <dfn export>root stacking context</dfn>, but other elements
  1937   may establish <dfn export>local stacking contexts</dfn>. Stacking contexts are inherited.
  1938   A local stacking context is atomic; boxes in other stacking contexts may not come
  1939   between any of its boxes.
  1941   An element that establishes a local stacking context generates a box that has
  1942   two stack levels: one for the stacking context it creates (always ''0'') and one
  1943   for the stacking context to which it belongs (given by the 'z-index' property).
  1945   An element’s box has the same stack level as its parent’s box unless
  1946   given a different stack level with the 'z-index' property.
  1948   <pre class="propdef">
  1949   Name: z-index
  1950   Value: auto | &lt;integer>
  1951   Initial: auto
  1952   Applies to: positioned elements
  1953   Inherited: no
  1954   Animatable: &lt;integer>
  1955   Percentages: N/A
  1956   Media: visual
  1957   Computed value: as specified
  1958   </pre>
  1960   For a positioned box, the 'z-index' property specifies:
  1962   <ol>
  1963     <li>
  1964     The stack level of the box in the current stacking context.
  1966     <li>
  1967     Whether the box establishes a stacking context.
  1968   </ol>
  1970   Values have the following meanings:
  1972   <dl dfn-for="z-index" dfn-type="value">
  1973     <dt><dfn>&lt;integer></dfn></dt>
  1974     <dd>
  1975       This integer is the stack level of the generated box in the current stacking
  1976       context. The box also establishes a new stacking context.
  1978     <dt><dfn>auto</dfn></dt>
  1979     <dd>
  1980       The stack level of the generated box in the current stacking context is 0. The box
  1981       does not establish a new stacking context unless it is the root element.
  1982   </dl>
  1984   In the following example, the stack levels of the boxes (named with their "id"
  1985   attributes) are: "text2"=0, "image"=1, "text3"=2, and "text1"=3. The "text2" stack level
  1986   is inherited from the root box. The others are specified with the 'z-index' property.
  1988   <div class="example">
  1989     <pre class="lang-html">
  1990     &lt;!DOCTYPE html>
  1991     &lt;html>
  1992         &lt;head>
  1993             &lt;title>Z-order positioning&lt;/title>
  1994             &lt;style type="text/css">
  1995                 .pile {
  1996                 position: absolute;
  1997                 left: 2in;
  1998                 top: 2in;
  1999                 width: 3in;
  2000                 height: 3in;
  2002             &lt;/style>
  2003         &lt;/head>
  2004         &lt;body>
  2005             &lt;p>
  2006                 &lt;img id="image" class="pile"
  2007                     src="butterfly.png" alt="A butterfly image"
  2008                     style="z-index: 1">
  2009             &lt;div id="text1" class="pile"
  2010                     style="z-index: 3">
  2011                 This text will overlay the butterfly image.
  2012             &lt;/div>
  2013             &lt;div id="text2">
  2014                 This text will be beneath everything.
  2015             &lt;/div>
  2016             &lt;div id="text3" class="pile"
  2017                     style="z-index: 2">
  2018                 This text will underlay text1, but overlay the butterfly image
  2019             &lt;/div>
  2020         &lt;/body>
  2021     &lt;/html>
  2022     </pre>
  2024     This example demonstrates the notion of <em>transparency</em>. The default behavior of
  2025     the background is to allow boxes behind it to be visible. In the example, each box
  2026     transparently overlays the boxes below it. This behavior can be overridden by using one
  2027     of the existing <a href="http://www.w3.org/TR/CSS2/colors.html#background-properties">background properties</a>.
  2028   </div>
  2030 <h2 id="det-stacking-context">
  2031 Detailed stacking context</h2>
  2033 <h3 id="definitions-stack">
  2034 Definitions</h3>
  2036   <dl dfn-for="tree-order" dfn-type="algo">
  2037     <dt>Tree Order</dt>
  2038     <dd>
  2039       The preorder depth-first traversal of the <em>rendering</em> tree, in logical (not
  2040       visual) order for bidirectional content, after taking into account properties
  2041       that move boxes around.
  2043     <dt>Element</dt>
  2044     <dd>
  2045       In this description, "element" refers to actual elements, pseudo-elements, and
  2046       anonymous boxes. Pseudo-elements and anonymous boxes are treated as descendants
  2047       in the appropriate places. For example, an outside list marker comes before an
  2048       adjoining '::before' box in the line box, which comes before the content of the
  2049       box, and so forth.
  2050   </dl>
  2051 <!-- End section: Definitions -->
  2053 <h3 id="painting-order">
  2054 Painting order</h3>
  2056   The bottom of the stack is the furthest from the user, the top of the stack is the
  2057   nearest to the user:
  2059   <figure>
  2060     <img src="images/stack.png" alt="A stacking context with four layers">
  2061     <figcaption>Schematic diagram of a stacking context with four layers.</figcaption>
  2062   </figure>
  2064   The stacking context background and most negative positioned stacking contexts
  2065   are at the bottom of the stack, while the most positive positioned stacking
  2066   contexts are at the top of the stack.
  2068   The canvas is transparent if contained within another, and given a UA-defined
  2069   color if it is not. It is infinite in extent and contains the root element.
  2070   Initially, the <a>viewport</a> is anchored with its top left corner at the
  2071   canvas origin.
  2073   The painting order for the descendants of an element generating a stacking
  2074   context (see the 'z-index' property) is:
  2076   <ol>
  2077     <li>If the element is a root element:
  2078       <ol>
  2079         <li>background color of element over the entire canvas.</li>
  2080         <li>
  2081           background image of element, over the entire canvas, anchored at the origin
  2082           that would be used if it was painted for the root element.
  2083         </li>
  2084       </ol>
  2085     </li>
  2086     <li>
  2087       If the element is a block, list-item, or other block equivalent:
  2088       <ol>
  2089         <li>background color of element unless it is the root element.</li>
  2090         <li>background image of element unless it is the root element.</li>
  2091         <li>column rule of the element.</li>
  2092         <li>border of element.</li>
  2093       </ol>
  2094       Otherwise, if the element is a block-level table:
  2095       <ol>
  2096         <li>table backgrounds (color then image) unless it is the root element.</li>
  2097         <li>column group backgrounds (color then image).</li>
  2098         <li>column backgrounds (color then image).</li>
  2099         <li>row group backgrounds (color then image).</li>
  2100         <li>row backgrounds (color then image).</li>
  2101         <li>cell backgrounds (color then image).</li>
  2102         <li>cell column rule for multi-column.</li>
  2103         <li>all table borders (in tree order for separated borders).</li>
  2104       </ol>
  2105     </li>
  2106     <li>
  2107       Stacking contexts formed by positioned descendants with negative z-indices
  2108       (excluding 0) in z-index order (most negative first) then tree order.
  2109     </li>
  2110     <li>
  2111       For all its in-flow, non-positioned, block-level descendants in tree order: If the
  2112       element is a block, list-item, or other block equivalent:
  2113       <ol>
  2114         <li>background color of element.</li>
  2115         <li>background image of element.</li>
  2116         <li>column rule of the element.</li>
  2117         <li>border of element.</li>
  2118       </ol>
  2119       Otherwise, the element is a table:
  2120       <ol>
  2121         <li>table backgrounds (color then image).</li>
  2122         <li>column group backgrounds (color then image).</li>
  2123         <li>column backgrounds (color then image).</li>
  2124         <li>row group backgrounds (color then image).</li>
  2125         <li>row backgrounds (color then image).</li>
  2126         <li>cell backgrounds (color then image).</li>
  2127         <li>cell column rule (multi-column).</li>
  2128         <li>all table borders (in tree order for separated borders).</li>
  2129       </ol>
  2130     </li>
  2131     <li>
  2132       All non-positioned <a>floating</a> descendants, in tree
  2133       order. For each one of these, treat the element as if it created a new stacking
  2134       context, but any positioned descendants and descendants which actually create
  2135       a new stacking context are considered part of the parent stacking context,
  2136       not this new one.
  2137     </li>
  2138     <li>If the element is an inline element that generates a stacking context, then:
  2139       <ol>
  2140         <li>For each line box that the element is in:
  2141           <ol>
  2142             <li>
  2143               Jump to <a href="#each-box">7.2.1</a> for the box(es) of the element
  2144               in that line box (in tree order).
  2145             </li>
  2146           </ol>
  2147         </li>
  2148       </ol>
  2149     </li>
  2150     <li>
  2151         Otherwise: first for the element, then for all its in-flow, non-positioned,
  2152         block-level descendants in tree order:
  2153         <ol>
  2154           <li>
  2155             If the element is a block-level replaced element, then: the replaced
  2156             content, atomically.
  2157           </li>
  2158           <li>Otherwise, for each line box of that element:
  2159             <ol>
  2160               <li id="each-box">
  2161                 For each box that is a child of that element, in that line box, in
  2162                 tree order:
  2163                 <ol>
  2164                   <li>background color of element.</li>
  2165                   <li>background image of element.</li>
  2166                   <li>column rule of the element.</li>
  2167                   <li>border of element.</li>
  2168                   <li>For inline elements:
  2169                     <ol>
  2170                       <li>
  2171                         For all the elements in-flow, non-positioned,
  2172                         inline-level children that are in this line box, and
  2173                         all runs of text inside the element that is on this
  2174                         line box, in tree order:
  2175                         <ol>
  2176                           <li>If this is a run of text, then:
  2177                             <ol>
  2178                               <li>
  2179                                 any underlining affecting the text
  2180                                 of the element, in tree order of the
  2181                                 elements applying the underlining
  2182                                 (such that the deepest element’s
  2183                                 underlining, if any, is painted
  2184                                 topmost and the root element’s
  2185                                 underlining, if any, is drawn
  2186                                 bottommost).
  2187                               </li>
  2188                               <li>
  2189                                 any overlining affecting the text of
  2190                                 the element, in tree order of the
  2191                                 elements applying the overlining
  2192                                 (such that the deepest element’s
  2193                                 overlining, if any, is painted
  2194                                 topmost and the root element’s
  2195                                 overlining, if any, is drawn
  2196                                 bottommost).
  2197                               </li>
  2198                               <li>the text</li>
  2199                               <li>
  2200                                 any line-through affecting the text
  2201                                 of the element, in tree order of the
  2202                                 elements applying the line-through
  2203                                 (such that the deepest element’s
  2204                                 line-through, if any, is painted
  2205                                 topmost and the root element’s
  2206                                 line-through, if any, is drawn
  2207                                 bottommost).
  2208                               </li>
  2209                             </ol>
  2210                           </li>
  2211                           <li>
  2212                             Otherwise, jump to <a href="#each-box">7.2.1</a>
  2213                             for that element
  2214                           </li>
  2215                         </ol>
  2216                       </li>
  2217                     </ol>
  2218                   </li>
  2219                   <li>For inline-block and inline-table elements:
  2220                     <ol>
  2221                       <li>
  2222                         For each one of these, treat the element as if it
  2223                         created a new stacking context, but any positioned
  2224                         descendants and descendants which actually create a
  2225                         new stacking context are considered part of the
  2226                         parent stacking context, not this new one.
  2227                       </li>
  2228                     </ol>
  2229                   </li>
  2230                   <li>For inline-level replaced elements:
  2231                     <ol>
  2232                       <li>the replaced content, atomically.</li>
  2233                     </ol>
  2234                   </li>
  2235                   <li>
  2236                     Optionally, the outline of the element (see <a href="#stack-order-step-ten">10 below</a>).
  2237                   </li>
  2238                 </ol>
  2239                 <p class="note">
  2240                   Note, some of the boxes may have been generated by line
  2241                   splitting or the Unicode bidirectional algorithm.
  2242                 </p>
  2243               </li>
  2244             </ol>
  2245           </li>
  2246           <li>
  2247             Optionally, if the element is block-level, the outline of the element
  2248             (see <a href="#stack-order-step-ten">10 below</a>).
  2249           </li>
  2250       </ol>
  2251     </li>
  2252     <li>
  2253       All positioned, opacity or transform descendants, in tree order that fall
  2254       into the following categories:
  2255       <ol>
  2256         <li>
  2257           All positioned descendants with 'z-index: auto' or 'z-index: 0', in tree order.
  2259           For those with 'z-index: auto', treat the element as if it created a new
  2260           stacking context, but any positioned descendants and descendants which actually
  2261           create a new stacking context should be considered part of the parent stacking
  2262           context, not this new one.
  2264           For those with 'z-index: 0' treat the stacking context generated atomically.
  2265         </li>
  2266         <li>
  2267           All opacity descendants with 'opacity' less than ''1'', in tree order, create a
  2268           stacking context generated atomically.
  2269         </li>
  2270         <li>
  2271           All transform descendants with 'transform' other than ''transform/none'', in tree order, create
  2272           a stacking context generated atomically.
  2273         </li>
  2274       </ol>
  2275     </li>
  2276   <li>
  2277     Stacking contexts formed by positioned descendants with z-indices greater than or
  2278     equal to 1 in z-index order (smallest first) then tree order.
  2279   </li>
  2280   <li id="stack-order-step-ten">
  2281     Finally, implementations that do not draw outlines in steps above must draw outlines
  2282     from this stacking context at this stage. (It is recommended to draw outlines in
  2283     this step and not in the steps above.)
  2284   </li>
  2285 </ol>
  2286 <!-- End section: Painting order -->
  2288 <h3 id="stacking-notes">
  2289 Notes</h3>
  2291   The background of the root element is only painted once, over the whole canvas.
  2293   While the backgrounds of bidirectional inlines are painted in tree order, they
  2294   are positioned in visual order. Since the positioning of inline backgrounds is
  2295   unspecified in CSS, the exact result of these two requirements is UA-defined.
  2296   A future version of CSS may define this in more detail.
  2297 <!-- End section: Notes -->
  2298 <!-- End section: Detailed stacking context -->
  2300 <h2 id="ack">
  2301 Acknowledgments</h2>
  2303   This module would not have been possible without input and support from many
  2304   helpful people. Thanks to Bert Bos, Tantek &Ccedil;elik, Anton Prowse,
  2305   Rossen Atanassov, Chris Jones, John Jansen, Sylvain Galineau.
  2306 <!-- End section: Acknowledgments -->
  2308 <!--
  2309  ██████  ██     ██    ███    ██    ██  ██████   ████████  ██████
  2310 ██    ██ ██     ██   ██ ██   ███   ██ ██    ██  ██       ██    ██
  2311 ██       ██     ██  ██   ██  ████  ██ ██        ██       ██
  2312 ██       █████████ ██     ██ ██ ██ ██ ██   ████ ██████    ██████
  2313 ██       ██     ██ █████████ ██  ████ ██    ██  ██             ██
  2314 ██    ██ ██     ██ ██     ██ ██   ███ ██    ██  ██       ██    ██
  2315  ██████  ██     ██ ██     ██ ██    ██  ██████   ████████  ██████
  2316 -->
  2318 <h2 class="no-num" id="changes">Changes</h2>
  2320 <h3 id="changes-201207">
  2321 Changes since the 7 February 2012 WD</h3>
  2323   The following significant changes were made since the
  2324   <a href="http://www.w3.org/TR/2012/WD-css3-positioning-20120207/">7 February 2012 Working Draft</a>
  2326   <ul>
  2327     <li>Added Rossen Atanassov as a new editor
  2328     <li>Added ''sticky'' keyword to the 'position' property to define the sticky
  2329       positioning behavior.
  2330     <li>Added logical offset keywords 'offset-before', 'offset-end', 'offset-after'
  2331       and 'offset-start'
  2332     <li>Added new attachment properties 'attachment-type', 'attachment-top', 'attachment-right',
  2333       'attachment-bottom', 'attachment-left', 'attachment'
  2334     <li>Removed 'clip' property section.
  2335   </ul>

mercurial