blob: 8b6e97987866a25125451492c35018936c11d7a6 (
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
|
---
title: <var>
slug: Web/HTML/Element/var
tags:
- HTML
- Web
translation_of: Web/HTML/Element/var
---
<div>{{HTMLRef}}</div>
<div>HTML Variable元素(<var>)表示数学表达式或编程上下文中的变量名称。尽管该行为取决于浏览器,但通常使用当前字体的斜体形式显示。</div>
<h2 id="概述">概述</h2>
<p><strong><var> 标签</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="/zh-CN/docs/Web/Guide/HTML/Content_categories#短语元素(phrasing content)">phrasing content</a>.</td>
</tr>
<tr>
<td>规范元素</td>
<td><a href="https://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="/zh-CN/docs/Web/HTML/Global_attributes" title="HTML/Global attributes">全局属性</a><span style="line-height: 21px;">.</span></p>
<h2 id="DOM_接口">DOM 接口</h2>
<p>本元素支持 <code><a href="/zh-CN/docs/Web/API/Element" title="DOM/element">HTMLElement</a></code> 接口</p>
<div class="note">
<p><strong>提示: </strong>Gecko 1.9.2 开始, Firefox支持本元素使用 <a href="/zh-CN/docs/Web/API/HTMLSpanElement">HTMLSpanElement</a> 接口。</p>
</div>
<h2 id="默认样式">默认样式</h2>
<pre class="brush:css">var {
font-style: italic;
}
</pre>
<h2 id="示例">示例</h2>
<pre class="brush:html"><p> A simple equation: <var>x</var> = <var>y</var> + 2 </p>
</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>
<h3 id="Overriding_the_default_style">Overriding the default style</h3>
<p>Using CSS, you can override the default style for the <code><var></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 class="brush:css">var {
font: bold 15px "Courier", "Courier New", monospace;
}</pre>
<h4 id="HTML">HTML</h4>
<pre class="brush:html"><p>The variables <var>minSpeed</var> and <var>maxSpeed</var> control
the minimum and maximum speed of the apparatus in revolutions
per minute (RPM).</p></pre>
<p>This HTML uses <code><var></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>
<div>{{Specifications}}</div>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>{{Compat}}</div>
|