@import styles not working in a media query

前端 未结 7 1851
难免孤独
难免孤独 2020-12-06 16:20

I am trying to import a style based off a media query but the import is not being triggered If i put styles directly in the media query they are rendered to the page.

<
7条回答
  •  萌比男神i
    2020-12-06 16:37

    I had the same problem and after searching without finding a good solution, I ended up moving the media queries to the imported css instead. And in fact all the style sheets are downloaded even if they are not applied anyway (see CSS media queries).

    Then what's the point of having separate files? For me, it keeps things organized. Using your example:

    @import url(min480.css); /* min-width: 480px */
    @import url(min600.css); /* min-width: 600px */
    

    Then on the min600.css:

    /* min600.css */
    @media only screen and (min-width: 600px) {
       header {
          text-align: left; 
       }
       body {
          background: green;
       }
    }
    

提交回复
热议问题