Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> CSS

CSS से इमेज पर टेक्स्ट को टॉप-लेफ्ट में पोज़िशन करें

इमेज पर टेक्स्ट को टॉप-लेफ्ट (ऊपर बाएं) कोने में रखने के लिए 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() फंक्शन उपयोग करें
  1. CSS से इमेज पर बटन कैसे जोड़ें? CSS से इमेज पर बटन कैसे जोड़ें?

    CSS से इमेज पर बटन जोड़ने का कोड निम्नलिखित है:उदाहरण<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> img{    width: 100%; } div {    position: relative;    width

  1. CSS से टेक्स्ट बटन कैसे स्टाइल करें? CSS से टेक्स्ट बटन कैसे स्टाइल करें?

    CSS का उपयोग करके विभिन्न रंगों और शैलियों के टेक्स्ट बटन बनाए जा सकते हैं। इस उदाहरण में पांच अलग-अलग प्रकार के बटन (Success, Info, Warning, Danger, Default) दिखाए गए हैं जिनमें होवर इफेक्ट भी शामिल है। उदाहरण <!DOCTYPE html> <html> <head> <meta name=viewport content=width=

  1. CSS से ग्लोइंग टेक्स्ट कैसे बनाएं? CSS से ग्लोइंग टेक्स्ट कैसे बनाएं?

    CSS से ग्लोइंग टेक्स्ट बनाने के लिए, कोड निम्नानुसार है -उदाहरण<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style>    body {       background-color: rgb(0, 0, 0);