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

CSS में ::before और ::after स्यूडो-एलिमेंट्स

CSS ::before और ::after स्यूडो-एलिमेंट्स का उपयोग क्रमशः किसी एलिमेंट से पहले और बाद में कुछ सामग्री डालने के लिए किया जाता है।

उदाहरण

आइए CSS ::before और CSS ::after स्यूडो-एलिमेंट्स का एक उदाहरण देखें:

<!DOCTYPE html> <html> <head> <style> div:nth-of-type(1) p:nth-child(2)::after {    content: " BUZZINGA!";    background: orange;    padding: 5px; } div:nth-of-type(2) p:nth-child(2)::before {    content: "Harry:";    background-color: lightblue;    font-weight: bold;    padding: 5px; } </style> </head> <body> <div> <p>Nobody: </p> <p>Sheldon Cooper:</p> </div><hr><div> <p><q>Death Eaters arrive</q></p> <p><q>Expecto Patronum!</q></p> </div> </body> </html>

आउटपुट

यह निम्नलिखित आउटपुट देगा:

CSS में ::before और ::after स्यूडो-एलिमेंट्स

एक और उदाहरण

आइए CSS ::before और CSS ::after स्यूडो-एलिमेंट्स का एक और उदाहरण देखें:

<!DOCTYPE html> <html> <head> <title>Center Alignment using CSS Margin</title> <style> #yinyangSymbol {    width: 100px;    height: 50px;    background: #fff;    border-color: #000;    border-style: solid;    border-width: 2px 2px 50px 2px;    border-radius: 100%;    position: relative; } #yinyangSymbol::before {    content: "";    position: absolute;    top: 50%;    left: 0;    background: #fff;    border: 18px solid #000;    border-radius: 100%;    width: 14px;    height: 14px; } #yinyangSymbol::after {    content: "";    position: absolute;    top: 50%;    left: 50%;    background: #000;    border: 18px solid #fff;    border-radius:100%;    width: 14px;    height: 14px; } div{    width: 50%;    margin: 10px auto;    border:4px solid black; } #text {    border: 4px solid black;    background-color: grey;    color: white;    text-align: center; } </style> </head> <body> <div id="main"> <div> <div id="yinyangSymbol"></div> </div> <div id="text">Be Centered & Balanced</div> </div> </body> </html>

आउटपुट

यह निम्नलिखित आउटपुट देगा:

CSS में ::before और ::after स्यूडो-एलिमेंट्स

  1. - CSS से फ्लेक्स आइटम्स को क्षैतिज रूप से सेट करें

    flex-direction: row flex-direction प्रॉपर्टी को row मान के साथ उपयोग करके फ्लेक्स-आइटम्स को क्षैतिज रूप से सेट करें। उदाहरण <!DOCTYPE html> <html> <head> <style> .mycontainer { display: flex; flex-direction: row; background-color: #2C3E50;

  1. CSS में ::first-letter Pseudo-element CSS में ::first-letter Pseudo-element

    यह CSS Pseudo Element किसी एलिमेंट के कंटेंट के पहले अक्षर को सिलेक्ट करता है। हालांकि, यह काम नहीं करता यदि एलिमेंट इनलाइन-लेवल है।उदाहरणआइए CSS ::first-letter pseudo element के लिए एक उदाहरण देखते हैं:<!DOCTYPE html> <html> <head> <style> div{ background-color: #32485d; bor

  1. CSS में border-style प्रॉपर्टी CSS में border-style प्रॉपर्टी

    CSS border-style प्रॉपर्टी का उपयोग किसी एलिमेंट के लिए बॉर्डर स्टाइल स्पेसिफाई करने के लिए किया जाता है। हम border-top-style, border-right-style, border-left-style और border-right-style प्रॉपर्टीज़ का उपयोग करके इंडिविजुअल साइड्स के लिए बॉर्डर-स्टाइल भी परिभाषित कर सकते हैं।सिंटैक्सCSS border प्रॉप