是否可以通过媒体查询将CSS文件包含到另一个CSS文件中? [英] Is it possible to include a CSS file into another CSS file with a media query?

查看:433
本文介绍了是否可以通过媒体查询将CSS文件包含到另一个CSS文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的CSS文件,我想包括其他CSS文件的特殊情况下使用媒体查询。

I have a large CSS file, and I would like to include other CSS files for special cases using media queries.

使用 @import 在CSS中像这样:

Is it safe to use @import in CSS like this:

@media only screen and (max-width: 480px) {    
    @import url('/css/styles-480.css');    
}


推荐答案

文件,如果需要,我建议您并行下载CSS文件:

Instead of importing within a CSS file, I would recommend that you download the CSS file in parallel if it is required:

<link media="only screen and (max-width: 480px)"
href="/css/styles-480.css" type="text/css" rel="stylesheet" />

使用 @import 的问题是第二个文件只有在包含 @import 的CSS文件完全下载并解析后才下载。无论是覆盖所有规则还是某些规则,此方法速度更快,因为它不会顺序加载文件。

The problem with using @import is that the second file is only downloaded after the CSS file containing @import is completely downloaded and parsed. Regardless of whether you are overriding all your rules or some of your rules, this approach is faster, since it doesn't load the files sequentially.

这篇关于是否可以通过媒体查询将CSS文件包含到另一个CSS文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆