CSS Layout - The position Property

Start from the beginning
                                        

<p>Try to <b>scroll</b> inside this frame to understand how sticky positioning works.</p>
<p>Note: IE/Edge 15 and earlier versions do not support sticky position.</p>

<div>I am sticky!</div>

<div style="padding-bottom:2000px">
  <p>In this example, the sticky element sticks to the top of the page (top: 0), when you reach its scroll position.</p>
  <p>Scroll back up to remove the stickyness.</p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p>
</div>

</body>
</html>

 ______________________________________________________________________________________________________________________________

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

______________________________________________________________________________________________________________________________

<!DOCTYPE html>
<html>
<head>
<style>
div.relative {
    position: relative;
    left: 30px;
    border: 3px solid #73AD21;
}
</style>
</head>
<body>

<h2>position: relative;</h2>

<p>An element with position: relative; is positioned relative to its normal position:</p>

<div>
This div element has position: relative;
</div>

</body>
</html>

 ______________________________________________________________________________________________________________________________

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

______________________________________________________________________________________________________________________________

<!DOCTYPE html>
<html>
<head>
<style>
div.static {
    position: static;
    border: 3px solid #73AD21;
}
</style>
</head>
<body>

<h2>position: static;</h2>

<p>An element with position: static; is not positioned in any special way; it is
always positioned according to the normal flow of the page:</p>

<div>
This div element has position: static;
</div>

</body>
</html>

______________________________________________________________________________________________________________________________

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

______________________________________________________________________________________________________________________________

<!DOCTYPE html>
<html>
<head>
<style>
div.fixed {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 300px;
    border: 3px solid #73AD21;
}
</style>
</head>
<body>

<h2>position: fixed;</h2>

<p>An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled:</p>

<div>
This div element has position: fixed;
</div>

</body>
</html>

______________________________________________________________________________________________________________________________

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

______________________________________________________________________________________________________________________________

<!DOCTYPE html>
<html>
<head>
<style>
div.relative {
    position: relative;
    width: 400px;
    height: 200px;
    border: 3px solid #73AD21;
}

div.absolute {
    position: absolute;
    top: 80px;
    right: 0;
    width: 200px;
    height: 100px;
    border: 3px solid #73AD21;
}
</style>
</head>
<body>

<h2>position: absolute;</h2>

<p>An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed):</p>

<div>This div element has position: relative;
  <div>This div element has position: absolute;</div>
</div>

</body>
</html>

______________________________________________________________________________________________________________________________

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

______________________________________________________________________________________________________________________________

You've reached the end of published parts.

⏰ Last updated: Dec 01, 2018 ⏰

Add this story to your Library to get notified about new parts!

Information Technology NotesWhere stories live. Discover now