From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/html/element/var/index.html | 128 ++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 files/zh-cn/web/html/element/var/index.html (limited to 'files/zh-cn/web/html/element/var') diff --git a/files/zh-cn/web/html/element/var/index.html b/files/zh-cn/web/html/element/var/index.html new file mode 100644 index 0000000000..25c6460a5f --- /dev/null +++ b/files/zh-cn/web/html/element/var/index.html @@ -0,0 +1,128 @@ +--- +title: +slug: Web/HTML/Element/var +tags: + - HTML + - Web +translation_of: Web/HTML/Element/var +--- +
+ +
+ +
{{HTMLRef}}
+ +
+ +
HTML Variable元素(<var>)表示数学表达式或编程上下文中的变量名称。尽管该行为取决于浏览器,但通常使用当前字体的斜体形式显示。
+ +

概述

+ +

<var> 标签表示变量的名称,或者由用户提供的值。

+ + + + + + + + + + + + + + + + + + + + +
允许内容Phrasing content
标签闭合Both start and end tags are required
允许的父级元素Any element that accepts phrasing content.
规范元素HTML, "The var element"
+ +

属性

+ +

本元素仅支持 全局属性.

+ +

DOM 接口

+ +

本元素支持 HTMLElement 接口

+ +
+

提示: Gecko 1.9.2 开始, Firefox支持本元素使用 HTMLSpanElement 接口。

+
+ +

默认样式

+ +
var {
+  font-style: italic;
+}
+
+ +

示例

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

A simple equation: x = y + 2

+ +
+

The output:

+ +

{{EmbedLiveSample("Basic_example", 650,80)}}

+
+ +
+

Overriding the default style

+ +

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

+ +

CSS

+ +
var {
+  font: bold 15px "Courier", "Courier New", monospace;
+}
+ +

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>
+ +

This HTML uses <var> to enclose the names of two variables.

+ +

Result

+ +

{{EmbedLiveSample("Overriding_the_default_style", 650, 120)}}

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-var-element', '<var>')}}{{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', 'textlevel-semantics.html#the-var-element', '<var>')}}{{Spec2('HTML5 W3C')}}
+ +

Browser compatibility

+ +

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

+ +

{{Compat("html.elements.var")}}

+
-- cgit v1.2.3-54-g00ecf