The position CSS property determines which of the positioning schemes is used to calculate the position of a box.
object.style.position = "value"; <'position'> = static | relative | absolute | sticky | fixed static The box is not a positioned box, and is laid out according to the rules of its parent formatting context.
relative The box is laid out as static, then offset from the resulting position.
absolute The box is positioned and sized solely in reference to its absolute positioning containing block. It is taken out of flow, meaning it has no impact on the size or position of its siblings and ancestors, and does not participate in its parent's formatting context.
sticky Identical to relative, except that its offsets are automatically adjusted in reference to the nearest ancestor scroll container's scrollport in whichever axes the inset properties are not both auto, to try to keep the box in view within its containing block as the user scrolls.
fixed Same as absolute, except the box is positioned and sized relative to a fixed positioning containing block.
<!doctype html>
<html>
<head>
<style>
img
{
background-color: black;
position: fixed;
right: 50px;
top: 50px;
}
</style>
</head>
<body>
<p>fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed</p>
<img alt="Happy Face" src="/assets/svg/HappyFace.svg">
<p>fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed</p>
<p>fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed</p>
<p>fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed</p>
<p>fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed fixed</p>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
img
{
background-color: black;
position: relative;
right: 50px;
top: 50px;
}
</style>
</head>
<body>
<p>relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative</p>
<img alt="Happy Face" src="/assets/svg/HappyFace.svg">
<p>relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative</p>
<p>relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative</p>
<p>relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative</p>
<p>relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative relative</p>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
img
{
background-color: black;
position: static;
right: 50px;
top: 50px;
}
</style>
</head>
<body>
<p>static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static</p>
<img alt="Happy Face" src="/assets/svg/HappyFace.svg">
<p>static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static</p>
<p>static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static</p>
<p>static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static</p>
<p>static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static static</p>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
img
{
background-color: black;
position: sticky;
right: 50px;
top: 50px;
}
</style>
</head>
<body>
<p>sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky</p>
<img alt="Happy Face" src="/assets/svg/HappyFace.svg">
<p>sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky</p>
<p>sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky</p>
<p>sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky</p>
<p>sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky sticky</p>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
img
{
background-color: black;
right: 50px;
top: 50px;
}
</style>
</head>
<body>
<button onmouseover="myfunction(innerHTML)">initial</button>
<button onmouseover="myfunction(innerHTML)">absolute</button>
<button onmouseover="myfunction(innerHTML)">fixed</button>
<button onmouseover="myfunction(innerHTML)">relative</button>
<button onmouseover="myfunction(innerHTML)">static</button>
<button onmouseover="myfunction(innerHTML)">sticky</button>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<img alt="Happy Face" src="/assets/svg/HappyFace.svg">
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<script>
function myfunction(myparameter)
{
document.querySelector("img").style.position = myparameter;
}
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<style>
img
{
background-color: black;
right: 50px;
top: 50px;
}
</style>
</head>
<body>
<button>initial</button>
<button>absolute</button>
<button>fixed</button>
<button>relative</button>
<button>static</button>
<button>sticky</button>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<img alt="Happy Face" src="/assets/svg/HappyFace.svg">
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<p>position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position position</p>
<script>
function myfunction(myparameter)
{
document.querySelector("img").style.position = myparameter;
}
const myelements = document.querySelectorAll("button");
for(let myelement of myelements)
{
myelement.addEventListener("mouseover", function(){myfunction(myelement.innerHTML)});
}
</script>
</body>
</html>