最好的方法来包括CSS?为什么使用@import? [英] Best way to include CSS? Why use @import?

查看:175
本文介绍了最好的方法来包括CSS?为什么使用@import?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想知道使用 @import 将样式表导入现有的样式表,而不是仅仅添加另一个样式表的优势/目的...

Basically I am wondering what is the advantage / purpose of using @import to import stylesheets into an existing stylesheet versus just adding another ...

<link rel="stylesheet" type="text/css" href="" />

到文档头部?

推荐答案

从页面速度的角度来看,CSS文件中的 @import 几乎从不使用,因为它可以防止样式表被下载同时。例如,如果样式表A包含文本:

From a page speed standpoint, @import from a CSS file should almost never be used, as it can prevent stylesheets from being downloaded concurrently. For instance, if stylesheet A contains the text:

@import url("stylesheetB.css");

,那么在下载第一个样式表之前,第二个样式表的下载可能无法开始。另一方面,如果两个样式表都在主HTML页面的< link> 元素中引用,则两者都可以同时下载。如果两个样式表总是加载在一起,也可以将它们简单地合并到一个文件中。

then the download of the second stylesheet may not start until the first stylesheet has been downloaded. If, on the other hand, both stylesheets are referenced in <link> elements in the main HTML page, both can be downloaded at the same time. If both stylesheets are always loaded together, it can also be helpful to simply combine them into a single file.

有时候会出现 @import 是合适的,但它们通常是例外,而不是规则。

There are occasionally situations where @import is appropriate, but they are generally the exception, not the rule.

这篇关于最好的方法来包括CSS?为什么使用@import?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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