aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/@import/index.html
blob: 8fb3a8aefa91e45f517f9607b039c51f958d6779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: '@import'
slug: Web/CSS/@import
tags:
  - '@import'
  - CSS
translation_of: Web/CSS/@import
---
<div>{{CSSRef}}</div>

<h2 id="概述">概述</h2>

<p><strong><code>@import </code></strong><a href="/en-US/docs/Web/CSS">CSS</a><a href="/en-US/docs/Web/CSS/At-rule">@规则</a>,用于从其他样式表导入样式规则。这些规则必须先于所有其他类型的规则,{{cssxref("@charset")}} 规则除外; 因为它不是一个<a href="/zh-CN/docs/Web/CSS/Syntax#nested_statements">嵌套语句</a>,@import不能在<a href="/zh-CN/docs/Web/CSS/At-rule#Conditional_Group_Rules">条件组的规则</a>中使用。</p>

<p>因此,用户代理可以避免为不支持的媒体类型检索资源,作者可以指定依赖媒体的@import规则。这些条件导入在URI之后指定逗号分隔的<a href="/en-US/docs/Web/CSS/Media_Queries/Using_media_queries">媒体查询</a>。在没有任何媒体查询的情况下,导入是无条件的。指定所有的媒体具有相同的效果。</p>

<h2 id="语法">语法</h2>

<pre class="eval">@import <em>url</em>;
@import <em>url</em> <em>list-of-media-queries</em>;
</pre>

<p>其中:</p>

<dl>
 <dt style="margin: 0 40px;"><em>url</em></dt>
 <dd style="margin: 0 40px;">是一个表示要引入资源位置的 {{cssxref("&lt;string&gt;")}} 或者 {{cssxref("&lt;uri&gt;")}} 。 这个 URL 可以是绝对路径或者相对路径。 要注意的是这个 URL 不需要指明一个文件; 可以只指明包名,然后合适的文件会被自动选择 (e.g. <strong>chrome://communicator/skin/</strong>). <a href="/en-US/docs/Mozilla/Tech/XUL/Tutorial/The_Chrome_URL">See here</a> 了解更多。</dd>
 <dt style="margin: 0 40px;"><em>list-of-media-queries</em></dt>
 <dd style="margin: 0 40px;">是一个逗号分隔的 <a href="/en-US/docs/Web/CSS/Media_Queries/Using_media_queries">媒体查询</a> 条件列表,决定通过URL引入的 CSS 规则 在什么条件下应用。如果浏览器不支持列表中的任何一条媒体查询条件,就不会引入URL指明的CSS文件。</dd>
</dl>

<h2 id="正规语法">正规语法</h2>

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="示例">示例</h2>

<pre class="brush:css">@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);
</pre>

<h2 id="技术规格">技术规格</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">技术规格</th>
   <th scope="col">Status</th>
   <th scope="col">备注</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Media Queries', '#media0', '@import')}}</td>
   <td>{{Spec2('CSS3 Media Queries')}}</td>
   <td>扩展语法以支持任何媒体查询,而不仅仅是简单的<a href="/en-US/docs/Web/CSS/@media#Media_types">媒体类型</a></td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'cascade.html#at-import', '@import')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>支持用{{cssxref("&lt;string&gt;")}}直接表示样式表的url,<br>
    并要求<code>@import</code>规则必须在CSS文档的开头。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#the-cascade', '@import')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>初始定义</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>5.5</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>5.5</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>