Search code examples
cssmedia-queries

CSS Media Queries For Mobile Devices Not Working


I am working with media queries to start making my site more responsive. However, the media queries work perfectly fine on my PC (Chrome) but when viewing on a mobile device (iPad and iPhone) the media queries don't seem to take effect. I have the viewport tag in the head but am guessing I'm missing something else....

CSS

@media (min-width:320px) { 
    /* smartphones, iPhone, portrait 480x320 phones */ 
    #mainText {
        color: pink;
    }
}
@media (min-width:481px) { 
    /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ 
    #mainText {
        color: blue;
    }
}
@media (min-width:641px) { 
    /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ 
    #mainText {
        color: red;
    }
}
@media (min-width:961px) { 
    /* tablet, landscape iPad, lo-res laptops ands desktops */ 
    #mainText {
        color: yellow;
    }
}
@media (min-width:1025px) { 
    /* big landscape tablets, laptops, and desktops */ 
    #mainText {
        color: green;
    }
}
@media (min-width:1281px) { 
    /* hi-res laptops and desktops */ 
    #mainText {
        color: purple;
    }
}

HTML

<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<div id="mainText">
    <h1>Text</h1>
    <h2>Text</h2>
</div>

Solution

  • There seems to be a filter in your css

    filter: brightness(1%);
    

    Now because you're not adding any vendor prefixes for webkit, chrome is just deciding to ignore it. You can either remove this rule or add the following to your css.

    -webkit-filter: brightness(1%);
    filter: brightness(1%);
    

    Cheers and Happy coding!