问题描述
我已经阅读过关于CSS @import
作为一个坏的做法,并想知道我使用的方法。
$ b $我目前正在使用WordPress构建一个网站,它通过链接引用导入每个插件的样式表,并且主样式表以相同的方式链接,但是,主样式表目前包含多个
@import
声明,我相信我应该将标题或移动到他们使用的适当页面(其中两个仅在某些页面上使用)。 我的关注是否合理,使用这些 @import
声明有何影响?
我认为你应该使用 LINK
c $ c> @import 在样式块的顶部,否则它将无法工作。
$ b
import
- 导入允许您将一个样式表导入到另一个样式表。这与链接方案略有不同,因为您可以在链接的样式表中导入样式表。
使用@import时最常见的原因是旧的浏览器无法识别@import,因此您可以隐藏样式
I've read about CSS @import
as a bad practice, and was wondering about the methods I'm using.
I'm currently building a website using WordPress, which imports each plugin's stylesheets by link references, and the main stylesheet is linked in the same manner, however, the main stylesheet currently contains several @import
declarations, which I believe I should be moving into the header or into the appropriate pages that they're used in (having two of them are only used on certain pages).
Are my concerns justified, and what are the implications of using those @import
declarations?
I think you should use LINK
for simplicity—you have to remember to put @import
at the top of the style block or else it won’t work. It turns out that avoiding @import is better for performance.
link
- Linking is the first method for including an external style sheet on your Web pages. It is intended to link together your Web page with your style sheet.
import
- Importing allows you to import one style sheet into another. This is slightly different than the link scenario, because you can import style sheets inside a linked style sheet.
The most common reason given for using @import instead is because older browsers didn't recognize @import, so you could hide styles from them.
This link will solve your all queries
What's the Difference Between @import and link for CSS?
这篇关于使用@import声明一个坏的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!