在线文档教程
CSS

@进口 | @import

@import

@import CSS@规则,用于从其他样式表导入样式规则。这些规则必须先于所有其他类型的规则,@charset 规则除外; 因为它不是一个嵌套语句,@import不能在条件组的规则中使用。

@import url("fineprint.css") print; @import url("bluish.css") projection, tv; @import 'custom.css'; @import url("chrome://communicator/skin/" @import "common.css" screen, projection; @import url('landscape.css') screen and (orientation:landscape

所以,用户代理可以避免为不支持的媒体类型检索资源,作者可以指定依赖媒体的@import规则。这些条件导入在URI之后指定逗号分隔的媒体查询。在没有任何媒体查询的情况下,导入是无条件的。指定所有的媒体具有相同的效果。

规范

@import url; @import url list-of-media-queries;

其中:

url 是一个表示要引入资源位置的<string>或者<uri>。 这个 URL 可以是绝对路径或者相对路径。 要注意的是这个 URL 不需要指明一个文件; 可以只指明包名,然后合适的文件会被自动选择 (e.g.chrome://communicator/skin/).See here了解更多。

形式语法

@import [ <string> | <url> ] [ <media-query-list> ]?;where <media-query-list> = <media-query># where <media-query> = <media-condition> | [ not | only ]? <media-type> [ and <media-condition-without-or> ]? where <media-condition> = <media-not> | <media-and> | <media-or> | <media-in-parens> <media-type> = <ident> <media-condition-without-or> = <media-not> | <media-and> | <media-in-parens> where <media-not> = not <media-in-parens> <media-and> = <media-in-parens> [ and <media-in-parens> ]+ <media-or> = <media-in-parens> [ or <media-in-parens> ]+ <media-in-parens> = ( <media-condition> ) | <media-feature> | <general-enclosed> where <media-feature> = ( [ <mf-plain> | <mf-boolean> | <mf-range> ] ) <general-enclosed> = [ <function-token> <any-value> ) ] | ( <ident> <any-value> ) where <mf-plain> = <mf-name> : <mf-value> <mf-boolean> = <mf-name> <mf-range> = <mf-name> [ '<' | '>' ]? '='? <mf-value> | <mf-value> [ '<' | '>' ]? '='? <mf-name> | <mf-value> '<' '='? <mf-name> '<' '='? <mf-value> | <mf-value> '>' '='? <mf-name> '>' '='? <mf-value> where <mf-name> = <ident> <mf-value> = <number> | <dimension> | <ident> | <ratio>

规范

SpecificationStatusComment
CSS Cascading and Inheritance Level 3The definition of '@import' in that specification.Candidate Recommendation
Media QueriesThe definition of '@import' in that specification.RecommendationExtended the syntax to support any media query and not only simple media types.
CSS Level 2 (Revision 1)The definition of '@import' in that specification.RecommendationAdded support for <string> to denote the url of a stylesheet, and requirement to insert the @import rule at the beginning of the CSS document.
CSS Level 1The definition of '@import' in that specification.RecommendationInitial definition

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support(Yes)(Yes)(Yes)5.5(Yes)(Yes)

FeatureAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support(Yes)(Yes)(Yes)5.5(Yes)(Yes)