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

CSS में @media At-rules


CSS @media नियम का उपयोग एक ही स्टाइल शीट में विभिन्न मीडिया टाइप्स (जैसे print, screen, all, आदि) के लिए अलग-अलग स्टाइल्स स्पेसिफाई करने के लिए किया जाता है। यह आमतौर पर मीडिया टाइप्स की कॉमा-सेपरेटेड लिस्ट और CSS डिक्लेरेशन ब्लॉक द्वारा फॉलो किया जाता है जिसमें टारगेट मीडिया के लिए स्टाइल नियम होते हैं।

सिंटैक्स

निम्नलिखित सिंटैक्स है:

@media not | only mediatype and (expressions) { CSS-Code; }

उदाहरण

आइए CSS @media नियम का एक उदाहरण देखते हैं:

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { box-sizing: border-box; } .col { float: left; width: 20%; padding: 40px; } body { background-color: lemonchiffon; margin: 20px; } @media screen and (max-width: 850px) { .col { width: 50%; } body { background-color: mediumseagreen; } } @media screen and (max-width: 550px) { .col { width: 100%; } body { background-color: powderblue; } } </style> </head> <body> <div class="row"> <div class="col" style="background-color:#373;"> </div> <div class="col" style="background-color:#363;"> </div> <div class="col" style="background-color:#353;"> </div> <div class="col" style="background-color:#343;"> </div> <div class="col" style="background-color:#333;"> </div> </div> </body> </html>

आउटपुट

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

जब स्क्रीन साइज़ 850px से ऊपर है -

CSS में @media At-rules

जब स्क्रीन साइज़ 550px और 850px के बीच है -

CSS में @media At-rules

जब स्क्रीन साइज़ 550px से नीचे है -

CSS में @media At-rules

उदाहरण

आइए CSS @media नियम का एक और उदाहरण देखते हैं:

<!DOCTYPE html> <html> <head> <style type="text/css"> p { background-origin: content-box; background-repeat: no-repeat; background-size: cover; box-shadow: 0 0 3px black; padding: 20px; background-origin: border-box; } @media screen and (max-width: 900px) { p{ background: url("https://www.tutorialspoint.com/swing/images/swing.jpg"); color: #c303c3; } } @media screen and (max-width: 500px) { p { color: black; background: url("https://www.tutorialspoint.com/cplusplus/images/cplusplus.jpg"); } } </style> </head> <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. 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>

आउटपुट

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

जब स्क्रीन साइज़ 500px से ऊपर है -

CSS में @media At-rules

जब स्क्रीन साइज़ 500px से नीचे है -

CSS में @media At-rules

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

    text-indent प्रॉपर्टी टेक्स्ट इंडेंटेशन के लिए CSS में text-indent प्रॉपर्टी का उपयोग करें। यह पैराग्राफ की पहली लाइन की इंडेंटेशन के लिए है। उदाहरण 1: 30px इंडेंट <!DOCTYPE html> <html> <head> <style> div { text-indent: 30px; } </style> </head> <body> <

  1. CSS में @import एट-नियम CSS में @import एट-नियम

    CSS @import नियम का उपयोग किसी विशिष्ट टार्गेट मीडिया के लिए स्टाइल जानकारी सेट करने के लिए किया जाता है, इम्पोर्ट की गई स्टाइलशीट्स के URL के बाद मीडिया टाइप्स निर्दिष्ट करके। सिंटैक्स निम्नलिखित सिंटैक्स है: @import url (/* file path */) mediatypes {    CSS-Code; } आइए CSS @import नियम क

  1. CSS में ::first-line स्यूडो-एलिमेंट CSS में ::first-line स्यूडो-एलिमेंट

    CSS का ::first-line स्यूडो-एलिमेंट किसी एलिमेंट की सामग्री की पहली लाइन को चुनता है। हालांकि, यदि टेक्स्ट वाले कंटेनर की चौड़ाई निश्चित नहीं है, तो लाइन की लंबाई विंडो के आकार के अनुसार बदल सकती है। उदाहरण आइए CSS ::first-line स्यूडो-एलिमेंट का एक उदाहरण देखें: <!DOCTYPE html> <html> &l