Why we use Position Absolute in CSS? - Tryit Editor for Web Developers
Edit This Code:
See Result »
<html> <head> <style> div.relative { position: relative; width: 500px; height: 200px; border: 5px solid brown; } div.absolute { position: absolute; top: 80px; right: 0; width: 300px; height: 100px; border: 3px solid red; } </style> </head> <body> <h2>Position: absolute;</h2> <p><b>An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed):</b></p> <div class="relative"> <img src="logo.jpg"/> <div class="absolute"> <img src="logo.jpg"/> </div> </div> </body> </html>
Result: