media query max width and height code example

Example 1: media query

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

Example 2: min and max width media query

@media (max-width: 989px) and (min-width: 768px) {}

Example 3: hegith specific css in media query

/* Exact height */
@media (height: 360px) {
  div {
    color: red;
  }
}

/* Minimum height */
@media (min-height: 25rem) {
  div {
    background: yellow;
  }
}

/* Maximum height */
@media (max-height: 40rem) {
  div {
    border: 2px solid blue;
  }
}

Example 4: what is a max and min width media query

/* What this query really means, is If [device width] is less than or equal to 600px, then do */
@media only screen and (max-width: 600px)  {...}

/* What this query really means, is If [device width] is greater than or equal to 600px, then do */
@media only screen and (min-width: 600px) {...}

Tags:

Css Example