position

  • Revision slug: CSS/position
  • Revision title: position
  • Revision id: 25391
  • Created:
  • Creator: mmclark
  • Is current revision? No
  • Comment 12 words added

Revision Content

{{ CSSRef() }}

Summary

The position CSS property chooses alternative rules for positioning elements, designed to be useful for scripted animation effects.

  • {{ Xref_cssinitial() }}: static
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: no
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

A positioned element is an element whose computed position property is relative, absolute, or fixed.

An absolutely positioned element is an element whose computed position property is absolute or fixed.

The {{ Cssxref("top") }}, {{ Cssxref("right") }}, {{ Cssxref("bottom") }}, and {{ Cssxref("left") }} properties specify the position of positioned elements.

Syntax

position:  static | relative | absolute | fixed | {{ cssxref("inherit") }}

Values

static
Normal behavior.  The top, right, bottom, and left properties do not apply.
relative
Lay out all elements as though the element were not positioned, and then adjust the element's position, without changing layout (and thus leaving a gap for the element where it would have been had it not been positioned).  The effect of position:relative on table-*-group, table-row, table-column, table-cell, and table-caption elements is undefined.
absolute
Do not leave space for the element.  Instead, position it at a specified position relative to its closest positioned ancestor or to the containing block. Absolutely positioned boxes can have margins, they do not collapse with any other margins.
fixed
Do not leave space for the element.  Instead, position it at a specified position relative to the screen's viewport and doesn't move when scrolled. When printing, position it at that fixed position on every page.

Examples

Relative Positioning

<style></style>

One

One

One

One

Notes

For relatively positioned elements, the {{ Cssxref("top") }} or {{ Cssxref("bottom") }} property specifies the vertical offset from the normal position and the {{ Cssxref("left") }} or {{ Cssxref("right") }} property specifies the horizontal offset.

For absolutely positioned elements, the {{ Cssxref("top") }}, {{ Cssxref("right") }}, {{ Cssxref("bottom") }}, and {{ Cssxref("left") }} properties specify offsets from the edge of the element's containing block (what the element is positioned relative to). The margin of the element is then positioned inside these offsets.

Most of the time, absolutely positioned elements have auto values of {{ Cssxref("height") }} and {{ Cssxref("width") }} computed to fit the contents of the element. However, non-replaced absolutely positioned elements can be made to fill the available space by specifying (as other than auto) both {{ Cssxref("top") }} and {{ Cssxref("bottom") }} and leaving {{ Cssxref("height") }} unspecified (that is, auto). Likewise for {{ Cssxref("left") }}, {{ Cssxref("right") }}, and {{ Cssxref("width") }}.

Except for the case just described of absolutely positioned elements filling the available space:

  • If both {{ Cssxref("top") }} and {{ Cssxref("bottom") }} are specified (technically, not auto), {{ Cssxref("top") }} wins.
  • If both {{ Cssxref("left") }} and {{ Cssxref("right") }} are specified, {{ Cssxref("left") }} wins when {{ Cssxref("direction") }} is ltr (English, horizontal Japanese, etc.) and {{ Cssxref("right") }} wins when {{ Cssxref("direction") }} is rtl (Arabic, Hebrew, etc.).

Browser compatibility

Browser Lowest version fixed value
Internet Explorer 4.0 7.0
Firefox (Gecko) 1.0 (1.0) 1.0 (1.0)
Opera 4.0 4.0
Safari (WebKit) 1.0 (85) 1.0 (85)

Specifications

See also

{{ Cssxref("display") }}, {{ Cssxref("float") }}, {{ Cssxref("top") }}, {{ Cssxref("right") }}, {{ Cssxref("bottom") }}, {{ Cssxref("left") }}

{{ languages( { "de": "de/CSS/position", "es": "es/CSS/position", "fr": "fr/CSS/position", "zh-cn": "cn/CSS/position" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h3>Summary</h3>
<p>The<code> position </code>CSS property chooses alternative rules for positioning elements, designed to be useful for scripted animation effects.</p>
<ul> <li>{{ Xref_cssinitial() }}:<code> static</code></li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: no</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<p>A <strong>positioned element</strong> is an element whose <a href="/en/CSS/computed_value" title="en/CSS/computed_value">computed</a> position property is <code>relative</code>, <code>absolute</code>, or <code>fixed</code>.</p>
<p>An <strong>absolutely positioned element</strong> is an element whose <a href="/en/CSS/computed_value" title="en/CSS/computed_value">computed</a> position property is <code>absolute</code> or <code>fixed</code>.</p>
<p>The {{ Cssxref("top") }}, {{ Cssxref("right") }}, {{ Cssxref("bottom") }}, and {{ Cssxref("left") }} properties specify the position of positioned elements.</p>
<h3>Syntax</h3>
<pre class="eval">position:  static | relative | absolute | fixed | {{ cssxref("inherit") }}</pre>
<h3>Values</h3>
<dl> <dt>static</dt> <dd>Normal behavior.  The<code> top</code>,<code> right</code>,<code> bottom</code>, and<code> left </code>properties do not apply.</dd> <dt>relative</dt> <dd>Lay out all elements as though the element were not positioned, and then adjust the element's position, without changing layout (and thus leaving a gap for the element where it would have been had it not been positioned).  The effect of<code> position:relative </code>on<code> table-*-group</code>,<code> table-row</code>,<code> table-column</code>,<code> table-cell</code>, and<code> table-caption </code>elements is undefined.</dd> <dt>absolute</dt> <dd>Do not leave space for the element.  Instead, position it at a specified position relative to its closest positioned ancestor or to the containing block. Absolutely positioned boxes can have margins, they do not collapse with any other margins.</dd> <dt>fixed</dt> <dd>Do not leave space for the element.  Instead, position it at a specified position relative to the screen's viewport and doesn't move when scrolled. When printing, position it at that fixed position on <em>every page</em>.</dd>
</dl>
<h3>Examples</h3>
<p>Relative Positioning</p>
&lt;style&gt;<!--[CDATA[
 div.test_image { width: 50px; height: 50px; background: red; float: left; margin: 0 1em 1em 1em; }
 div.test_image p { color: white; font-weight: bold; margin: 1em; }
]]-->&lt;/style&gt;
<div class="test_image"><p>One</p></div>
<div class="test_image"><p>One</p></div>
<div class="test_image"><p>One</p></div>
<div class="test_image"><p>One</p></div>
<h3>Notes</h3>
<p>For relatively positioned elements, the {{ Cssxref("top") }} or {{ Cssxref("bottom") }} property specifies the vertical offset from the normal position and the {{ Cssxref("left") }} or {{ Cssxref("right") }} property specifies the horizontal offset.</p>
<p>For absolutely positioned elements, the {{ Cssxref("top") }}, {{ Cssxref("right") }}, {{ Cssxref("bottom") }}, and {{ Cssxref("left") }} properties specify offsets from the edge of the element's containing block (what the element is positioned relative to). The margin of the element is then positioned inside these offsets.</p>
<p>Most of the time, absolutely positioned elements have <code>auto</code> values of {{ Cssxref("height") }} and {{ Cssxref("width") }} computed to fit the contents of the element. However, non-replaced absolutely positioned elements can be made to fill the available space by specifying (as other than <code>auto</code>) both {{ Cssxref("top") }} and {{ Cssxref("bottom") }} and leaving {{ Cssxref("height") }} unspecified (that is, <code>auto</code>). Likewise for {{ Cssxref("left") }}, {{ Cssxref("right") }}, and {{ Cssxref("width") }}.</p>
<p>Except for the case just described of absolutely positioned elements filling the available space:</p>
<ul> <li>If both {{ Cssxref("top") }} and {{ Cssxref("bottom") }} are specified (technically, not <code>auto</code>), {{ Cssxref("top") }} wins.</li> <li>If both {{ Cssxref("left") }} and {{ Cssxref("right") }} are specified, {{ Cssxref("left") }} wins when {{ Cssxref("direction") }} is <code>ltr</code> (English, horizontal Japanese, etc.) and {{ Cssxref("right") }} wins when {{ Cssxref("direction") }} is <code>rtl</code> (Arabic, Hebrew, etc.).</li>
</ul>
<h3>Browser compatibility</h3>
<table class="standard-table"> <tbody> <tr> <th>Browser</th> <th>Lowest version</th> <th><code>fixed </code>value</th> </tr> <tr> <td>Internet Explorer</td> <td>4.0</td> <td><strong>7.0</strong></td> </tr> <tr> <td>Firefox (Gecko)</td> <td><strong>1.0</strong> (1.0)</td> <td>1.0 (1.0)</td> </tr> <tr> <td>Opera</td> <td><strong>4.0</strong></td> <td>4.0</td> </tr> <tr> <td>Safari (WebKit)</td> <td><strong>1.0</strong> (85)</td> <td>1.0 (85)</td> </tr> </tbody>
</table>
<h3>Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/visuren.html#choose-position" title="http://www.w3.org/TR/CSS21/visuren.html#choose-position">CSS 2.1 Visual formatting #position</a></li>
</ul>
<h3>See also</h3>
<p>{{ Cssxref("display") }}, {{ Cssxref("float") }}, {{ Cssxref("top") }}, {{ Cssxref("right") }}, {{ Cssxref("bottom") }}, {{ Cssxref("left") }}</p>
<p>{{ languages( { "de": "de/CSS/position", "es": "es/CSS/position", "fr": "fr/CSS/position", "zh-cn": "cn/CSS/position" } ) }}</p>
Revert to this revision