FANDOM


The position property is used in CSS and certain HTML elements. It selects alternative rules for positioning elements, designed to be useful for scripted animation effects. 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 top, right, bottom, and left properties specify the position of positioned elements.

Values

  • static - Normal behavior. The top, right, bottom, and left properties do not apply.
  • relative - Lays out all elements as though the element were not positioned, and then adjusts the element's position, without changing the 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 - Does not leave space for the element. Instead, it is positioned at a specified position relative to its closest positioned ancestor or to the containing block. Absolutely positioned boxes can have margins, as they do not collapse with any other margins.
  • fixed - Does not leave space for the element. Instead, it is positioned at a specified position relative to the screen's viewport and doesn't move when scrolled. When printing, it is positioned at that fixed position on every page.


For relatively positioned elements, the top or bottom property specifies the vertical offset from the normal position and the left or right property specifies the horizontal offset.

For absolutely positioned elements, the top, right, bottom, and 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 height and 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 top and bottom and leaving height unspecified (that is, auto). Likewise for left, right, and width.

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

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


HTML example:

<div style="position:fixed; top:200px; right:200px;">
TEXT
</div>


CSS example:

div {
     position:fixed;
     top:200px;
     right:200px;
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.