使用@import声明一个坏的做法吗? [英] Is using @import declarations a bad practice?

查看:135
本文介绍了使用@import声明一个坏的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

@import和CSS中的链接之间的区别


我已经阅读过关于CSS @import 作为一个坏的做法,并想知道我使用的方法。


$ b $我目前正在使用WordPress构建一个网站,它通过链接引用导入每个插件的样式表,并且主样式表以相同的方式链接,但是,主样式表目前包含多个 @import 声明,我相信我应该将标题移动到他们使用的适当页面(其中两个仅在某些页面上使用)。



我的关注是否合理,使用这些 @import 声明有何影响?

解决方案

我认为你应该使用 LINK c $ c> @import 在样式块的顶部,否则它将无法工作。


$ b
  • 链接是在Web页面上包含外部样式表的第一种方法。它旨在将您的网页与您的样式表链接在一起。



  • import




    • 导入允许您将一个样式表导入到另一个样式表。这与链接方案略有不同,因为您可以在链接的样式表中导入样式表。



    使用@import时最常见的原因是旧的浏览器无法识别@import,因此您可以隐藏样式





    about.com/od/beginningcss/f/css_import_link.htmrel =nofollow> @import和CSS的链接有什么区别?


    Possible Duplicate:
    Difference between @import and link in CSS

    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声明一个坏的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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