0

I am very confuse with the media query because when ever i apply media query it does not work properly is there ant sequence to write it in CSS file?

@media max-width(767px)  {body{background:red;}  }
@media max-width(992px)  {body{background:blue;}  }
@media max-width(1200px)  {body{background:#fff;}  }

Is there any proper sequence to write it according to the screen size?Is the any difference if i write it like this?

@media max-width(1200px)  {body{background:#fff;}  }
@media max-width(992px)  {body{background:blue;}  }
@media max-width(767px)  {body{background:red;}  }
Sumit Kumar
  • 493
  • 2
  • 5
  • 16

1 Answers1

3

You have to write your media as below.

Learn here:https://www.w3schools.com/cssref/css3_pr_mediaquery.asp

See here:https://jsfiddle.net/r60xs5j7/3/

@media only screen and (max-width: 767px) {body{background:#fff;}  }
@media only screen and (max-width: 992px)  {body{background:blue;}  }
@media only screen and (min-width: 1200px)  {body{background:red;}  }

and whenever you put them in css they have to work(Except for a case of override that you will need use !important)

See here(end of css):https://jsfiddle.net/r60xs5j7/5/

Note!

You need this meta in head tag to make media query works:

<meta name="viewport" content="width=device-width, initial-scale=1">
לבני מלכה
  • 15,925
  • 2
  • 23
  • 47