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

CSS से Z-Index का उपयोग करके ओवरलैपिंग एलिमेंट्स


CSS Z-Index प्रॉपर्टी का उपयोग करके डेवलपर एलिमेंट्स को एक-दूसरे के ऊपर स्टैक कर सकते हैं। Z-Index का मान पॉजिटिव या नेगेटिव हो सकता है।

नोट - यदि ओवरलैप होने वाले एलिमेंट्स में z-index स्पेसिफाई नहीं है तो वह एलिमेंट दिखेगा जो डॉक्यूमेंट में अंत में मेंशन किया गया है।

उदाहरण

आइए z-index प्रॉपर्टी का एक उदाहरण देखते हैं:

<!DOCTYPE html> <html> <head> <style> p { margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } div{ margin: auto; position: absolute; top:0; left: 0; right: 0; bottom: 0; } div:first-child { background-color: orange; width: 270px; height: 120px; z-index: -2; } div:last-child { width: 250px; height: 100px; z-index: -1; background-color: turquoise; } </style> </head> <body> <div></div> <p>Fortran was originally developed by a team at IBM in 1957 for scientific calculations...................</p> <div> </div> </body> </html>

आउटपुट

उपरोक्त कोड के लिए आउटपुट निम्नलिखित है:

CSS से Z-Index का उपयोग करके ओवरलैपिंग एलिमेंट्स

उदाहरण

आइए z-index प्रॉपर्टी का एक और उदाहरण देखते हैं:

<!DOCTYPE html> <html> <head> <style> p { background: url("https://www.tutorialspoint.com/tensorflow/images/tensorflow-mini-logo.jpg"); background-origin: content-box; background-repeat: no-repeat; background-size: cover; box-shadow: 0 0 3px black; padding: 20px; background-origin: border-box; } </style> </head> <h2>Demo</h2> <body> <p>This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text.</p> </body> </html>

आउटपुट

उपरोक्त कोड के लिए आउटपुट निम्नलिखित है:

CSS से Z-Index का उपयोग करके ओवरलैपिंग एलिमेंट्स

  1. CSS में एलिमेंट्स के बैकग्राउंड को स्टाइल करना CSS में एलिमेंट्स के बैकग्राउंड को स्टाइल करना

    background शॉर्टहैंड प्रॉपर्टी किसी एलिमेंट के बैकग्राउंड प्रॉपर्टीज़ को background एट्रिब्यूट से निर्दिष्ट करें। यह निम्न मान ले सकता है: background-color, background-image, background-repeat, background-position, background-clip, background-size, background-origin, background-attachment। सिंटैक्स

  1. CSS में z-index प्रॉपर्टी से एलिमेंट्स को लेयर्स में स्टैक करना CSS में z-index प्रॉपर्टी से एलिमेंट्स को लेयर्स में स्टैक करना

    CSS z-index प्रॉपर्टी का उपयोग करके डेवलपर एलिमेंट्स को एक-दूसरे के ऊपर स्टैक कर सकते हैं। z-index का मान पॉजिटिव या नेगेटिव हो सकता है। नोट: यदि ओवरलैप होने वाले एलिमेंट्स में z-index निर्दिष्ट नहीं है, तो वह एलिमेंट दिखाई देगा जो दस्तावेज़ में अंतिम बार उल्लिखित है। उदाहरण आइए z-index प्रॉपर्टी

  1. CSS से टेक्स्ट इंडेंटेशन CSS से टेक्स्ट इंडेंटेशन

    CSS text-indent प्रॉपर्टी हमें किसी एलिमेंट की पहली लाइन का इंडेंटेशन सेट करने में मदद करती है।सिंटैक्सCSS text-indent प्रॉपर्टी का सिंटैक्स निम्नलिखित है:Selector { text-indent: /*value*/ }उदाहरणनिम्नलिखित उदाहरण CSS text-indent प्रॉपर्टी को दर्शाते हैं।<!DOCTYPE html> <html> <head&g