सीएसएस ट्यूटोरियल

सीएसएस होम सीएसएस परिचय सीएसएस सिंटेक्स सीएसएस चयनकर्ता सीएसएस कैसे करें सीएसएस टिप्पणियाँ सीएसएस रंग सीएसएस पृष्ठभूमि सीएसएस बॉर्डर्स सीएसएस मार्जिन सीएसएस पैडिंग सीएसएस ऊंचाई/चौड़ाई सीएसएस बॉक्स मॉडल सीएसएस रूपरेखा सीएसएस पाठ सीएसएस फ़ॉन्ट्स सीएसएस प्रतीक सीएसएस लिंक सीएसएस सूचियां सीएसएस टेबल्स सीएसएस प्रदर्शन सीएसएस अधिकतम-चौड़ाई सीएसएस स्थिति सीएसएस जेड-इंडेक्स सीएसएस अतिप्रवाह सीएसएस फ्लोट सीएसएस इनलाइन-ब्लॉक सीएसएस संरेखित करें सीएसएस संयोजक सीएसएस छद्म वर्ग सीएसएस छद्म तत्व सीएसएस अस्पष्टता सीएसएस नेविगेशन बार सीएसएस ड्रॉपडाउन सीएसएस छवि गैलरी सीएसएस छवि स्प्राइट्स सीएसएस एटीआर चयनकर्ता सीएसएस फॉर्म सीएसएस काउंटर सीएसएस वेबसाइट लेआउट सीएसएस इकाइयां सीएसएस विशिष्टता सीएसएस !महत्वपूर्ण सीएसएस गणित कार्य

सीएसएस उन्नत

सीएसएस गोल कोनों सीएसएस सीमा छवियां सीएसएस पृष्ठभूमि सीएसएस रंग सीएसएस रंग कीवर्ड सीएसएस ग्रेडिएंट सीएसएस छाया सीएसएस पाठ प्रभाव सीएसएस वेब फ़ॉन्ट्स CSS 2D ट्रांसफ़ॉर्म CSS 3D ट्रांसफ़ॉर्म सीएसएस संक्रमण सीएसएस एनिमेशन सीएसएस टूलटिप्स सीएसएस शैली छवियां सीएसएस छवि प्रतिबिंब CSS ऑब्जेक्ट-फिट सीएसएस वस्तु-स्थिति सीएसएस मास्किंग सीएसएस बटन सीएसएस पेजिनेशन सीएसएस एकाधिक कॉलम सीएसएस यूजर इंटरफेस सीएसएस चर सीएसएस बॉक्स साइजिंग सीएसएस मीडिया प्रश्न सीएसएस एमक्यू उदाहरण सीएसएस फ्लेक्सबॉक्स

सीएसएस उत्तरदायी

आरडब्ल्यूडी परिचय आरडब्ल्यूडी व्यूपोर्ट आरडब्ल्यूडी ग्रिड व्यू आरडब्ल्यूडी मीडिया प्रश्न आरडब्ल्यूडी छवियां आरडब्ल्यूडी वीडियो आरडब्ल्यूडी फ्रेमवर्क आरडब्ल्यूडी टेम्पलेट्स

सीएसएस ग्रिड

ग्रिड परिचय ग्रिड कंटेनर ग्रिड आइटम

सीएसएस एसएएसएस

एसएएसएस ट्यूटोरियल

सीएसएस उदाहरण

सीएसएस टेम्पलेट्स सीएसएस उदाहरण सीएसएस प्रश्नोत्तरी सीएसएस अभ्यास सीएसएस प्रमाणपत्र

सीएसएस संदर्भ

सीएसएस संदर्भ सीएसएस चयनकर्ता सीएसएस कार्य सीएसएस संदर्भ कर्ण सीएसएस वेब सुरक्षित फ़ॉन्ट्स सीएसएस एनिमेटेबल सीएसएस इकाइयां सीएसएस पीएक्स-ईएम कनवर्टर सीएसएस रंग सीएसएस रंग मान सीएसएस डिफ़ॉल्ट मान सीएसएस ब्राउज़र समर्थन

CSS मीडिया क्वेरीज़ - उदाहरण


CSS मीडिया क्वेरीज़ - अधिक उदाहरण

आइए मीडिया प्रश्नों के उपयोग के कुछ और उदाहरण देखें।

विभिन्न उपकरणों के लिए एक अनुरूप स्टाइल शीट देने के लिए मीडिया क्वेरी एक लोकप्रिय तकनीक है। एक सरल उदाहरण प्रदर्शित करने के लिए, हम विभिन्न उपकरणों के लिए पृष्ठभूमि का रंग बदल सकते हैं:

उदाहरण

/* Set the background color of body to tan */
body {
  background-color: tan;
}

/* On screens that are 992px or less, set the background color to blue */
@media screen and (max-width: 992px) {
  body {
    background-color: blue;
  }
}

/* On screens that are 600px or less, set the background color to olive */
@media screen and (max-width: 600px) {
  body {
    background-color: olive;
  }
}

क्या आपको आश्चर्य है कि हम ठीक 992px और 600px का उपयोग क्यों करते हैं? वे वही हैं जिन्हें हम उपकरणों के लिए "विशिष्ट ब्रेकप्वाइंट" कहते हैं। आप हमारे उत्तरदायी वेब डिज़ाइन ट्यूटोरियल में विशिष्ट ब्रेकप्वाइंट के बारे में अधिक पढ़ सकते हैं


मेनू के लिए मीडिया प्रश्न

इस उदाहरण में, हम एक प्रतिक्रियाशील नेविगेशन मेनू बनाने के लिए मीडिया क्वेरी का उपयोग करते हैं, जो विभिन्न स्क्रीन आकारों पर डिज़ाइन में भिन्न होता है।

बड़ी स्क्रीन:

छोटे पर्दे:

उदाहरण

/* The navbar container */
.topnav {
  overflow: hidden;
  background-color: #333;
}

/* Navbar links */
.topnav a {
  float: left;
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

/* On screens that are 600px wide or less, make the menu links stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .topnav a {
    float: none;
    width: 100%;
  }
}


कॉलम के लिए मीडिया प्रश्न

मीडिया प्रश्नों का एक सामान्य उपयोग, एक लचीला लेआउट बनाना है। इस उदाहरण में, हम एक लेआउट बनाते हैं जो विभिन्न स्क्रीन आकारों के आधार पर चार, दो और पूर्ण-चौड़ाई वाले स्तंभों के बीच भिन्न होता है:

Large screens:

 

Medium screens:

 

Small screens:

Example

/* Create four equal columns that floats next to each other */
.column {
  float: left;
  width: 25%;
}

/* On screens that are 992px wide or less, go from four columns to two columns */
@media screen and (max-width: 992px) {
  .column {
    width: 50%;
  }
}

/* On screens that are 600px wide or less, make the columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
  }
}

Tip: A more modern way of creating column layouts, is to use CSS Flexbox (see example below). However, it is not supported in Internet Explorer 10 and earlier versions. If you require IE6-10 support, use floats (as shown above).

To learn more about the Flexible Box Layout Module, read our CSS Flexbox chapter.

To learn more about Responsive Web Design, read our Responsive Web Design Tutorial.

Example

/* Container for flexboxes */
.row {
  display: flex;
  flex-wrap: wrap;
}

/* Create four equal columns */
.column {
  flex: 25%;
  padding: 20px;
}

/* On screens that are 992px wide or less, go from four columns to two columns */
@media screen and (max-width: 992px) {
  .column {
    flex: 50%;
  }
}

/* On screens that are 600px wide or less, make the columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .row {
    flex-direction: column;
  }
}

Hide Elements With Media Queries

Another common use of media queries, is to hide elements on different screen sizes:

I will be hidden on small screens.

Example

/* If the screen size is 600px wide or less, hide the element */
@media screen and (max-width: 600px) {
  div.example {
    display: none;
  }
}

Change Font Size With Media Queries

You can also use media queries to change the font size of an element on different screen sizes:

Variable Font Size.

Example

/* If screen size is more than 600px wide, set the font-size of <div> to 80px */
@media screen and (min-width: 600px) {
  div.example {
    font-size: 80px;
  }
}

/* If screen size is 600px wide, or less, set the font-size of <div> to 30px */
@media screen and (max-width: 600px) {
  div.example {
    font-size: 30px;
  }
}

Flexible Image Gallery

In this example, we use media queries together with flexbox to create a responsive image gallery:

Example


Flexible Website

In this example, we use media queries together with flexbox to create a responsive website, containing a flexible navigation bar and flexible content.

Example


Orientation: Portrait / Landscape

Media queries can also be used to change layout of a page depending on the orientation of the browser.

You can have a set of CSS properties that will only apply when the browser window is wider than its height, a so called "Landscape" orientation:

Example

Use a lightblue background color if the orientation is in landscape mode:

@media only screen and (orientation: landscape) {
  body {
    background-color: lightblue;
  }
}

Min Width to Max Width

You can also use the (max-width: ..) and (min-width: ..) values to set a minimum width and a maximum width.

For example, when the browser's width is between 600 and 900px, change the appearance of a <div> element:

Example

@media screen and (max-width: 900px) and (min-width: 600px) {
  div.example {
    font-size: 50px;
    padding: 50px;
    border: 8px solid black;
    background: yellow;
  }
}

Using an additional value: In the example below, we add an additional media query to our already existing one using a comma (this will behave like an OR operator):

Example

/* When the width is between 600px and 900px OR above 1100px - change the appearance of <div> */
@media screen and (max-width: 900px) and (min-width: 600px), (min-width: 1100px) {
  div.example {
    font-size: 50px;
    padding: 50px;
    border: 8px solid black;
    background: yellow;
  }
}

CSS @media Reference

For a full overview of all the media types and features/expressions, please look at the @media rule in our CSS reference.

Tip: To learn more about responsive web design (how to target different devices and screens), using media query breakpoints, read our Responsive Web Design Tutorial.