Difference Between HTML LINK Media and CSS Media Queries

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

I know there are 2 ways to add Media queries:

HTML LINK:



        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 11:47

    Here is what W3C has to say about this:

    The media attribute says which media the resource applies to. The value must be a valid media query.

    [...]

    However, if the link is an external resource link, then the media attribute is prescriptive. The user agent must apply the external resource when the media attribute's value matches the environment and the other relevant conditions apply, and must not apply it otherwise.

    Note: The external resource might have further restrictions defined within that limit its applicability. For example, a CSS style sheet might have some @media blocks. This specification does not override such further restrictions or requirements.

    I tested the behavior in Chrome using the following markup:

    
    
    
    • Apparently, Chrome downloaded all CSS files regardless of screen resolution.
    • However, it applied the rules from matching stylesheet(s) only
      • And it honored all matching @media rules within the stylesheet

提交回复
热议问题