<var>
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:
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
Specifications
Specification |
---|
HTML Standard # the-var-element |
Browser compatibility
BCD tables only load in the browser