w3schools media query code example

Example 1: css media queries

@media only screen and (max-width: 1200px){
    /*Tablets [601px -> 1200px]*/
}
@media only screen and (max-width: 600px){
	/*Big smartphones [426px -> 600px]*/
}
@media only screen and (max-width: 425px){
	/*Small smartphones [325px -> 425px]*/
}

Example 2: media query

@media only screen and (max-width: 600px) {
  body {
    background-color: lightblue;
  }
}

Example 3: css media query

/* BOOSTRAP MEDIA BREAKPOINTS */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {  
  .selector {
  	background-color:#f00;
  }
}
 
/* Medium devices (tablets, 768px and up) The navbar toggle appears at this breakpoint */
@media (min-width: 768px) {  
}
 
/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) { 
}
 
/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {    
}

Example 4: media query

// Example media query syntax
@media only screen and (min-width: 768px) {
  .my-example-class {
    padding: 50px;
  }
}

// Best Practice
// keep default style for smallest screen size (portrait mobile, below 576px)
// and then proceed in assending order with media query like below

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }

// so on ...

Example 5: media query

/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {}

/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {}

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {}

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {}

/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {}

Example 6: media query

@media only screen and (max-width: 600px) {
  .class {
    // Your CSS
  }
}

Tags:

Misc Example