aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/html/element/var/index.html
blob: 25c6460a5f406538dfbdeab5cea0b024c839a97a (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
125
126
127
128
---
title: <var>
slug: Web/HTML/Element/var
tags:
  - HTML
  - Web
translation_of: Web/HTML/Element/var
---
<div></div>

<div></div>

<div>{{HTMLRef}}</div>

<div></div>

<div>HTML Variable元素(&lt;var&gt;)表示数学表达式或编程上下文中的变量名称。尽管该行为取决于浏览器,但通常使用当前字体的斜体形式显示。</div>

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

<p><strong>&lt;var&gt; 标签</strong>表示变量的名称,或者由用户提供的值。</p>

<table class="standard-table">
 <tbody>
  <tr>
   <td>允许内容</td>
   <td>Phrasing content</td>
  </tr>
  <tr>
   <td>标签闭合</td>
   <td>Both start and end tags are required</td>
  </tr>
  <tr>
   <td>允许的父级元素</td>
   <td>Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="HTML/Content categories#Phrasing content">phrasing content</a>.</td>
  </tr>
  <tr>
   <td>规范元素</td>
   <td><a href="http://www.whatwg.org/html/#the-var-element">HTML, "The <code>var</code> element"</a></td>
  </tr>
 </tbody>
</table>

<h2 id="属性">属性</h2>

<p><span style="line-height: 21px;">本元素仅支持 </span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">全局属性</a><span style="line-height: 21px;">.</span></p>

<h2 id="DOM_接口">DOM 接口</h2>

<p>本元素支持 <code><a href="/en-US/docs/DOM/element" title="DOM/element">HTMLElement</a></code> 接口</p>

<div class="note">
<p><strong>提示: </strong>Gecko 1.9.2 开始, Firefox支持本元素使用 <a href="/en-US/docs/DOM/span" title="DOM/span"><span style="font-family: courier new;">HTMLSpanElement</span></a> 接口。</p>
</div>

<h2 id="默认样式">默认样式</h2>

<pre class="brush:css">var {
  font-style: italic;
}
</pre>

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

<pre class="brush:html">&lt;p&gt; A simple equation: &lt;var&gt;x&lt;/var&gt; = &lt;var&gt;y&lt;/var&gt; + 2 &lt;/p&gt;
</pre>

<p>A simple equation: <var>x</var> = <var>y</var> + 2</p>

<div>
<p>The output:</p>

<p>{{EmbedLiveSample("Basic_example", 650,80)}}</p>
</div>

<div>
<h3 id="Overriding_the_default_style">Overriding the default style</h3>

<p>Using CSS, you can override the default style for the <code>&lt;var&gt;</code> element. In this example, variable names are rendered using bold Courier if it's available, otherwise it falls back to the default monospace font.</p>

<h4 id="CSS">CSS</h4>

<pre>var {
  font: bold 15px "Courier", "Courier New", monospace;
}</pre>

<h4 id="HTML">HTML</h4>

<pre>&lt;p&gt;The variables &lt;var&gt;minSpeed&lt;/var&gt; and &lt;var&gt;maxSpeed&lt;/var&gt; control
   the minimum and maximum speed of the apparatus in revolutions
   per minute (RPM).&lt;/p&gt;</pre>

<p>This HTML uses <code>&lt;var&gt;</code> to enclose the names of two variables.</p>

<h4 id="Result">Result</h4>

<p>{{EmbedLiveSample("Overriding_the_default_style", 650, 120)}}</p>

<h2 id="Specifications">Specifications</h2>

<table>
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-var-element', '&lt;var&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'textlevel-semantics.html#the-var-element', '&lt;var&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("html.elements.var")}}</p>
</div>