Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Media Queries not working in Angular8

I am running an angular app on CLI version 8. Everything was working fine last time I checked my code to github and build for production. But now when I try running it on localhost there seems to be a problem. The HTML files are not picking up the media queries from the CSS files. When I write my CSS out of the media queries everything works fine but inside media queries it doesn't work.

Also, when I try inspecting on chrome, the classes are attached on the HTML tags but CSS won't show. I don't know where I did a mistake. My guess is because of some build there caused an error or because of some npm package or may be some other reason.

These are the media queries I am using:

/* mobiles (landscape and portrait) */
@media only screen and (min-width: 320px) and (max-width: 500px) {}


/* iPads (portrait and landscape) ----------- */
@media only screen and (min-width: 550px) and (max-width: 800px) {}


/* Desktops and laptops ----------- */
@media only screen and (min-width: 850px) and (max-width: 1024px) {}

/* bigger laptops */
@media only screen and (min-width: 1224px) { }

Please help me out of this situation. Thanks in advance.

like image 460
neerav94 Avatar asked Nov 14 '25 19:11

neerav94


2 Answers

Media queries should be be at the end of your css file because css is read from top to bottom. The rule that is set last, is the one that will be executed

/* bigger laptops */
@media only screen and (min-width: 1224px) { }
/* Desktops and laptops ----------- */
@media only screen and (min-width: 850px) and (max-width: 1024px) {}
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-width: 550px) and (max-width: 800px) {}
/* mobiles (landscape and portrait) */
@media only screen and (min-width: 320px) and (max-width: 500px) {}
like image 50
Tzimpo Avatar answered Nov 17 '25 09:11

Tzimpo


Thanks for the help!

There seems to be some error in an npm package that I was using. Removed the package and everything is working fine as expected. The npm package that I was using was ngx-swiper-wrapper.

like image 41
neerav94 Avatar answered Nov 17 '25 07:11

neerav94



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!