CSS Position Property

  • Using the position property set the position of an element.
  • These are different types like static, relative, absolute, fixed, or sticky.

CSS Syntax→ position: static|absolute|fixed|relative|sticky;

CSS Static Position Property

  • This CSS position property is default. 
  • Elements are presented in the order they appear in document flow.
  • The elements will be positioned according to the normal flow of the page.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
position: static;
left: 10px;
top: 105px;
background-color: lightgray;
padding: 15px;

}
</style>
</head>
<body>

<h1>The Static position Property</h1>

<h2><a href="#">Home</a>      <a href="#">COURSE</a>      <a href="#">Ablout</a></h2>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Static position Property kindly scroll to show the best results.
</p>
</body>
</html>

CSS Absolute Position Property

  • The position of the element will be relative to the closest positioned ancestor.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
position: absolute;
left: 10px;
top: 105px;
background-color: lightgray;
padding: 15px;

}
</style>
</head>
<body>

<h1>The Absolute position Property</h1>

<h2><a href="#">Home</a>      <a href="#">COURSE</a>      <a href="#">Ablout</a></h2>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
</p><p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Absolute position Property kindly scroll to show the best results.
</p>
</body>
</html>

CSS Fixed Position Property

  • The position of the element will be positioned relative to the viewport.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
position: fixed;
left: 10px;
top: 105px;
background-color: lightgray;
padding: 15px;

}
</style>
</head>
<body>

<h1>The Fixed position Property</h1>

<h2><a href="#">Home</a>      <a href="#">COURSE</a>      <a href="#">Ablout</a></h2>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
<p>This is the Example of fixed position Property kindly scroll to show the best results.
</p>
</body>
</html>

CSS Relative Position Property

  • The element remains in the normal flow of the document but left, right, top, and bottom affects.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
position: relative;
left: 10px;
top: 105px;
background-color: lightgray;
padding: 15px;

}
</style>
</head>
<body>

<h1>The Relative position Property</h1>

<h2><a href="#">Home</a>      <a href="#">COURSE</a>      <a href="#">Ablout</a></h2>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
<p>This is the Example of Relative position Property kindly scroll to show the best results.
</p>
</body>
</html>

CSS Sticky Position Property

  • The element with position: sticky and top: 0 played a role between fixed & relative based on the position where it is placed.

Note:- Not supported in IE/Edge 15 or earlier. Supported in Safari from version 6.1 with a -webkit- prefix.

Example
<!DOCTYPE html>
<html>
<head>
<style>
div.sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: blue;
padding: 40px;
font-size: 20px;
color:white;
}
</style>
</head>
<body>

<h2>Use of Sticky Element</h2>
<p>Scroll down this page to see how sticky positioning works.</p>
<div class="sticky">Hiiii I am scroll sticky position</div>

<p>Some example text..</p>
<h2>Scroll back up again to "remove" the sticky position.</h2>
<p>On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab. Most controls offer a choice of using the look from the current theme or using a format that you specify directly.
To change the overall look of your document, choose new Theme elements on the Page Layout tab. To change the looks available in the Quick Style gallery, use the Change Current Quick Style Set command. Both the Themes gallery and the Quick Styles gallery provide reset commands so that you can always restore the look of your document to the original contained in your current template.
On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab. Most controls offer a choice of using the look from the current theme or using a format that you specify directly.
To change the overall look of your document, choose new Theme elements on the Page Layout tab. To change the looks available in the Quick Style gallery, use the Change Current Quick Style Set command. Both the Themes gallery and the Quick Styles gallery provide reset commands so that you can always restore the look of your document to the original contained in your current template.

</p>

</body>
</html>

CSS Defference between all Position Property

Example
<!DOCTYPE html>
<html>
<head>
<style>
#head1 {
position: static;
border: 2px solid blue;
width: 300px;
height: 100px;
background-color: #9ff29d;
}

#sub1 {
position: absolute;
border: 2px solid red;
top: 70px;
right: 15px;
background-color: #7c9aeb;
}

#head2 {
position: relative;
border: 2px solid blue;
width: 300px;
height: 100px;
background-color: #dfa1f7;
}

#sub2 {
position: absolute;
border: 2px solid red;
top: 70px;
right: 15px;
background-color: #9ec6f0;
}

#head3 {
position: absolute;
border: 2px solid blue;
width: 300px;
height: 100px;
top: 750px;
right: 15px;
background-color: #cc4774;
}

#sub3 {
position: absolute;
border: 2px solid red;
top: 70px;
right: 15px;
background-color: #695d61;
}

#head4 {
position: fixed;
border: 2px solid blue;
background-color: rgba(255,200,200,0.5);
width: 300px;
height: 100px;
bottom: 0;
left: 0;
right: 0;
background-color: #506e40;
}

#sub4 {
position: absolute;
border: 2px solid green;
top: 70px;
right: 15px;
background-color: white;
}
</style>
</head>
<body>

<h1>The position property:</h1>
<p>Complete defference between each position property like static, relative, absolute, fixed.</p>

<div id="head1"><h4>Use of static position property.</h4>
Hello is am head1 and my position property is static.
<div id="sub1">Hello is am sub1 and my position: absolute, right: 18px, top: 80px</div>
</div>

<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>


<div id="head2"><h4>Use of relative position property.</h4>
Hello is am head2 and my position property is relative.
<div id="sub2">Hello is am sub2 and my position: absolute, right: 18px, top: 80px</div>
</div>

<div id="head3"><h4>Use of absolute position property.</h4>
Hello is am head3 and my position property is absolute and top: 750px, right: 15px.
<div id="sub3">Hello is am sub3 and my position: absolute, right: 18px, top: 80px</div>
</div>


<div id="head4"><h4>Use of fixed position property.</h4>
Hello is am head4 and my position property is fixed, bottom: 0, left: 0, right: 0.
<div id="sub4">Hello is am sub4 and my position: absolute, right: 18px, top: 80px</div>
</div>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>
<p>Here is some text ...................</p>

</body>
</html>
English Hindi