इमेज पर टेक्स्ट को टॉप-लेफ्ट (ऊपर बाएं) कोने में रखने के लिए position: absolute के साथ top और left प्रॉपर्टीज़ का उपयोग करें।
उदाहरण: इमेज पर टॉप-लेफ्ट टेक्स्ट
<!DOCTYPE html>
<html>
<head>
<style>
.box {
position: relative;
display: inline-block;
max-width: 100%;
}
img {
width: 100%;
height: auto;
opacity: 0.6;
display: block;
}
.direction {
position: absolute;
top: 10px;
left: 19px;
font-size: 13px;
color: white;
background: rgba(0,0,0,0.5);
padding: 5px 10px;
border-radius: 3px;
}
</style>
</head>
<body>
<h1>हेडिंग वन</h1>
<p>नीचे दी गई इमेज में टेक्स्ट टॉप-लेफ्ट में है:</p>
<div class="box">
<img src="https://www.tutorialspoint.com/python/images/python_data_science.jpg" alt="Tutorial" width="800" height="400">
<div class="direction">टॉप लेफ्ट कॉर्नर</div>
</div>
</body>
</html>
चारों कोने पोज़िशनिंग सारांश
| पोज़िशन | CSS |
|---|---|
| टॉप-लेफ्ट | top: 10px; left: 10px; |
| टॉप-राइट | top: 10px; right: 10px; |
| बॉटम-लेफ्ट | bottom: 10px; left: 10px; |
| बॉटम-राइट | bottom: 10px; right: 10px; |
| सेंटर | top: 50%; left: 50%; transform: translate(-50%, -50%); |
आवश्यक संरचना
<div class="box"> <!-- position: relative -->
<img src="..."> <-- इमेज -->
<div class="label">...</div> <-- position: absolute -->
</div>
बेस्ट प्रैक्टिस
- पैरेंट:
position: relative(नया स्टैकिंग कॉन्टेक्स्ट) - चाइल्ड:
position: absolute - पढ़ने योग्यता: सेमी-ट्रांसपेरेंट बैकग्राउंड + कंट्रास्टिंग टेक्स्ट
- रिस्पॉन्सिव: % मान या
clamp()फंक्शन उपयोग करें