CSS Layout - The Position Property
CSS Layout - The Position Property
</body>
</html>
absolute positioning
The absolute positioning is used to position an element relative to the first
parent element that has a position other than static.
The box is taken out of the normal flow the box position is specified with the
top,right,bottom,left.
Relative-position: places an element relative to its current position with out
changing the layout around it.
absolute-position: places an element relative to its current position changing the
layout around it.
<!DOCTYPE html>
<html>
<head>
<style>
.parent {
border: 3px black dotted;
display:inline-block;
}
.box{
display:inline-block;
background:yellow;
width:100px;
height:100px;
}
#two{
top:20px;
left:20px;
background:green;
position:absolute;
}
</style>
</head>
<body>
<h2>absolute positioning</h2>
<div class="parent">
<div class="box" id="one">one</div>
<div class="box" id="two">two</div>
<div class="box" id="three">three</div>
</div>
</body>
</html>
Sticky positioning :
An element with position: sticky; is positioned based on the user's scroll
position.
A sticky element toggles between relative and fixed, depending on the scroll
position.
It is positioned relative until a given offset position is met in the viewport -
then it "sticks" in place (like position:fixed).
<!DOCTYPE html>
<html>
<head>
<style>
div.sticky {
position: sticky;
top: 0;
padding: 5px;
background-color: red;
border: 2px solid green;
}
</style>
</head>
<body>
<p>Try to <b>scroll</b> inside this frame to understand how sticky positioning works.</p>
<div class="sticky">I am sticky!</div>
<div style="padding-bottom:2000px"> This is CSIT
</div>
</body></html>