Media Queries: How to target desktop, tablet, and mobile?

前端 未结 16 2179
清酒与你
清酒与你 2020-11-21 04:53

I have been doing some research on media queries and I still don\'t quite understand how to target devices of certain sizes.

I want to be able to target desktop, ta

16条回答
  •  生来不讨喜
    2020-11-21 05:36

    One extra feature is you can also use-media queries in the media attribute of the tag.

    
    
    
    

    With this, the browser will download all CSS resources, regardless of the media attribute. The difference is that if the media-query of the media attribute is evaluated to false then that .css file and his content will not be render-blocking.

    Therefore, it is recommended to use the media attribute in the tag since it guarantees a better user experience.

    Here you can read a Google article about this issue https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-blocking-css

    Some tools that will help you to automate the separation of your css code in different files according to your media-querys

    Webpack https://www.npmjs.com/package/media-query-plugin https://www.npmjs.com/package/media-query-splitting-plugin

    PostCSS https://www.npmjs.com/package/postcss-extract-media-query

提交回复
热议问题