1

div.klase {
  background-color: aqua;
  height: 200px;
  width: 300px;
  border: 1px solid red;
  box-sizing: border-box;
}

@media screen and (max-width:500px;
) {
  .klase {
    background-color: pink;
  }
}
<div class="klase"></div>

First of all sorry if this question might be dumb , I'm trying to change its .klase color to pink when it is smaller than 500px . But it doesn't seem to work that way even though it's almost similiar to the other examples of media queries. Appreciate any help, thanks in advance.

Turnip
  • 35,836
  • 15
  • 89
  • 111
Edgaras
  • 69
  • 4
  • 1
    `div.klase` is more specific than `.klase` so your media block will not work. You also need to remove the `;` after `500px` – Turnip Jun 21 '18 at 11:18
  • Going off of @Turnip 's comment, specifying an element before a class like "div.klase" isn't necessary for most situations. – Matthew Beaudin Jun 21 '18 at 13:04

2 Answers2

2

It works with specificity. Try this way

div.klase {
  background-color: aqua;
  height: 200px;
  width: 300px;
  border: 1px solid red;
  box-sizing: border-box;
}

@media screen and (max-width:500px) {
  div.klase {
    background-color: pink;
  }
}
m4n0
  • 29,823
  • 27
  • 76
  • 89
Ajay.k
  • 111
  • 10
2

Check this

.klase {
  height: 200px;
  width: 300px;
  border: 1px solid red;
  box-sizing: border-box;
  background-color:aqua;
}

@media (max-width: 500px) {
  .klase {
    background-color:pink;
  }
}
<div class="klase"></div>
Abin Thaha
  • 4,493
  • 3
  • 13
  • 41