2

IE11 ignore my media queries and always using the mobile css.

the weird thing is that if i'll change the browser width, even for just 1-2 pixel, the browser will render itself and the media queries are shown.

i tried css lint and i have no errors in my css.

i have nothing special in my css. just plain css like this:

.div_example{
  width: 100px;
}

@media (min-width: 768px){
  .div_example{
    width: 300px;
  }
}

Has anyone encountered this problem?

Moran Gil
  • 21
  • 1
  • 4

4 Answers4

3

Had this exact thing occur. Just like you, if the window was resized the media queries would seemingly kick in. Was difficult to debug because opening up the developer console docked to the window also caused a resize and everything looked fine. Upon switching the developer console to a separate window I could see in the DOM explorer that the media queries were not applying.

Eventually I tracked it down to the media queries being inside of a style block that was in the body instead of the head. Relocating the style block to the head made IE11 correctly apply the media queries.

style in the body was not supported in IE11 (Using <style> tags in the <body> with other HTML) so it is not surprising there would be some weirdness.

Chase
  • 3,123
  • 1
  • 30
  • 35
0

Ran across this issue with IE11 today. Min & Max width media queries were not being applied. However, media query blocks based on a fixed size or other attributes (like -ms-high-contrast: none) Were being applied.

Fix was to add only screen since all also didn't work.

Does Not Work

@media (min-width: 1000px){ ... }
@media all and (min-width: 1000px) { ... }

Does Work

@media only screen and (min-width: 1000px) { ... }

Those should be the exact same and I have no idea why one works and the other doesn't but maybe this will save someone else a headache.

Bryce Howitson
  • 7,339
  • 18
  • 40
-1

You have to define the screen types, e.g...

https://responsivedesign.is/develop/browser-feature-support/media-queries-for-common-device-breakpoints

vicgoyso
  • 636
  • 1
  • 14
  • 35
-1

It always use mobile styles because you are using:

@media (min-width: 768px)

This condition will be true if your window width is more than 768px, try this:

@media (max-width: 768px)

Styles inside that media query will be applied when window width is less than 768px and probably that's what you want to achieve.

Mateusz Woźniak
  • 1,479
  • 1
  • 9
  • 10
  • 2
    They are using a mobile first approach so they are saying the CSS in the media query is not working and they always see the 100px width. They can't get their non-mobile CSS in the media query to activate. – Chase Aug 17 '18 at 23:04