Is it possible to include one CSS file in another?

是否有可能包含一个CSS文件在另一个?


Yes:

@import url("base.css");

Note:

  • The @import rule must precede all other rules (except the @charset rule); and
  • Additional @import statements require additional server requests.
  • Aggregate CSS into one file to avoid multiple HTTP requests. That is, copy the contents of base.css and special.css into base-special.css and reference only base-special.css ).

    In 2008, not all browsers supported @import (see Browser Compatibility).


    Yes. Importing CSS file into another CSS file is possible.

    It must be the first rule in the style sheet using the @import rule.

    @import "mystyle.css";
    @import url("mystyle.css");
    

    The only caveat is that older web browsers will not support it. In fact, this is one of the CSS 'hack' to hide CSS styles from older browsers.

    Refer to this list for browser support.


    The @import url("base.css"); works fine but bear in mind that every @import statement is a new request to the server. This might not be a problem for you, but when optimal performance is required you should avoid the @import .

    链接地址: http://www.djcxy.com/p/31844.html

    上一篇: 在CSS文件中使用相对URL,它相对于哪个位置?

    下一篇: 是否有可能包含一个CSS文件在另一个?