position: absolute का उपयोग
position: absolute एलिमेंट को नॉर्मल डॉक्यूमेंट फ्लो से निकाल देता है और इसे **निकटतम पोजिशन्ड एंसेस्टर** (जिसकी पोजिशन static न हो) के सापेक्ष पोजिशन करता है। यदि ऐसा कोई एंसेस्टर नहीं है, तो यह <html> (इनिशियल कंटेनिंग ब्लॉक) के सापेक्ष पोजिशन होता है।
उदाहरण
<!DOCTYPE html>
<html>
<head>
<style>
div.one {
position: relative;
width: 500px;
height: 150px;
border: 2px solid blue;
}
div.two {
position: absolute;
top: 70px;
right: 0;
width: 300px;
height: 50px;
border: 2px solid yellow;
}
</style>
</head>
<body>
<h2>position: absolute;</h2>
The position: absolute; property allows you to position element relative to the nearest positioned ancestor.
<div class="one">
div has position: relative;
<div class="two">div has position: absolute;</div>
</div>
</body>
</html>
महत्वपूर्ण: एब्सोल्यूट एलिमेंट अपने पैरेंट (यदि पोजिशन्ड) के पैडिंग बॉक्स के सापेक्ष पोजिशन होता है। z-index से स्टैक ऑर्डर नियंत्रित करें।