The CSS position property controls how an element is positioned relative to other elements on the page.
The 5 available values are:
The position property uses 4 other CSS properties: top, right, bottom, and left.
The element is positioned according to the standard rules of HTML and CSS layout. The default.
The element is offset relative to it's original location. The element remains in the document flow.
.child-box
{
position: relative;
left: 150px;
top: -90px;
}
<div class="parent-box">
Parent
<span class="child-box">
Child
</span>
Sibling
</div>
Article continues below Ad.
The element is offset relative to the browser window. The element is removed from the document flow.
.child-box
{
position: fixed;
left: 10px;
top: 10px;
}
<div class="parent-box">
Parent
<span class="child-box">
Child
</span>
Sibling
</div>
Article continues below Ad.
The element is offset relative to the html document or to the nearest parent element that is positioned relative. The element is removed from the document flow.
.child-box
{
position: absolute;
left: 50px;
top: 50px;
}
<div class="parent-box">
Parent
<span class="child-box">
Child
</span>
Sibling
</div>
Article continues below Ad.
A hybrid of relative and fixed. The element is positioned as relative within it's parent, until it crosses a threshold, at which point it becomes fixed.
.child-box
{
position: sticky;
top: 0;
}
<div class="child-box">
Child
</div>
/* This is a CSS rule */
byElementName, .byClass, #byId /* These are CSS selectors. */
{
/* This is a CSS declaration block */
property: value; /* This is a CSS declaration */
property: value; /* A CSS declaration assigns a value to a property */
}