Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS : Using same class within different media queries

I have the following code :

@media (min-width: 1200px) {
  .color {
    color: blue;
  }
}

@media (min-width: 992px) {
  .color {
    color: red;
  }
}

@media (min-width: 768px) {
  .color {
    color: green;
  }
}

@media (max-width: 767px) {

}
<div class="color">Wow ji</div>

No matter what the screen size, Wow ji appears in green color only. What am I doing wrong here ?

like image 235
Daud Avatar asked Sep 06 '26 09:09

Daud


2 Answers

In CSS, it is the last corresponding style that is applied, so in your code, as long as the screen is at least 768px, it will appear green.

You need either to set a max-width in the first tests, or do them in the inverse order.

like image 150
Kaddath Avatar answered Sep 07 '26 22:09

Kaddath


Because what you are saying is at 768px or higher you want .color to be green you need to swap the order of your media queries around or use max-width

like image 39
BritishSam Avatar answered Sep 07 '26 21:09

BritishSam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!