Difference Between HTML LINK Media and CSS Media Queries

前端 未结 2 1038
情歌与酒
情歌与酒 2020-12-06 11:22

I know there are 2 ways to add Media queries:

HTML LINK:



        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 11:44

    Regarding the stylesheet download, here is what the current spec draft says:

    User agents should re-evaluate media queries in response to changes in the user environment, for example if the device is tiled from landscape to portrait orientation, and change the behavior of any constructs dependent on those media queries accordingly.

    This means you can’t just evaluate each media-query and then download the appropriate stylesheets because the environment can change, causing the re-evaluation of these media-queries. I think it could be optimized, but for now all browsers download all stylesheets, regardless of media-queries.

    For your second question, specs don’t mention any difference between HTML- and CSS-declared media-queries. Nested media-queries are allowed since CSS3, and putting @media-rules in a stylesheet which is already tagged with media="…" should be the same as a pure CSS nested media-query.

提交回复
热议问题