CSS Position Property

The position property specifies the kind of positioning technique used for part (static, relative, mounted or absolute)

The position Property

The position property specifies the kind of positioning technique used for part.

There area unit four completely different position values:

  • static
  • relative
  • fixed
  • absolute

Elements area unit then positioned exploitation the highest, bottom, left, and right properties. However, these properties won’t work unless the position property is about 1st. They additionally work otherwise betting on the position worth.

position: static;

HTML parts area unit positioned static by default.

Static positioned parts don’t seem to be full of the highest, bottom, left, and right properties.

An element with position: static; isn’t positioned in any special way; it’s invariably positioned in step with the conventional flow of the page:

div.static {
position: static;
border: 1px solid #000;
}

position: relative;

An element with position: relative; is positioned relative to its traditional position.

Setting the highest, right, bottom, and left properties of a relatively-positioned component can cause it to be adjusted aloof from its traditional position. alternative content won’t be adjusted to suit into any gap left by the component.
div.relative {
position: relative;
left: 10px;
border: 1px solid #000;
}

position: fixed;

An element with position: fixed; is positioned relative to the viewport, which suggests it invariably stays within the same place even though the page is scrolled. The top, right, bottom, and left properties area unit accustomed position the component.
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 500px;
border: 1px solid #000;
}

position: absolute;

An element with position: absolute; is positioned relative to the closest positioned root (instead of positioned relative to the viewport, like fixed).


div.relative {
position: relative;
width: 800px;
height: 300px;
border: 1px solid #000;
}
div.absolute {
position: absolute;
top: 50px;
right: 0;
width: 500px;
height: 200px;
border: 1px solid #000;
}