<var>:变量元素
<var>
HTML 元素表示数学表达式或编程上下文中变量的名称。它通常使用当前字体的斜体版本呈现,尽管该行为取决于浏览器。
¥The <var>
HTML element represents the name of a variable in a mathematical expression or a programming context. It's typically presented using an italicized version of the current typeface, although that behavior is browser-dependent.
Try it
属性
使用说明
相关元素
¥Related elements
在 <var>
常用的上下文中使用的其他元素包括:
¥Other elements that are used in contexts in which <var>
is commonly used include:
如果你遇到错误地将 <var>
用于样式目的而不是语义目的的代码,你应该使用具有适当 CSS 的 <span>
,或者使用以下元素中的适当语义元素:
¥If you encounter code that is mistakenly using <var>
for style purposes rather than semantic purposes, you should either use a <span>
with appropriate CSS or, an appropriate semantic element among the following:
默认样式
¥Default style
大多数浏览器在渲染 <var>
时都会应用 font-style
到 "italic"
。这可以在 CSS 中重写,如下所示:
¥Most browsers apply font-style
to "italic"
when rendering <var>
. This can be overridden in CSS, like this:
var {
font-style: normal;
}
示例
基本示例
覆盖默认样式
¥Overriding the default style
使用 CSS,你可以覆盖 <var>
元素的默认样式。在此示例中,变量名称以粗体呈现,如果可用,则使用 Courier,否则它将回退到默认的等宽字体。
¥Using CSS, you can override the default style for the <var>
element. In this example, variable names are rendered in bold, using 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>
此 HTML 使用 <var>
括住两个变量的名称。
¥This HTML uses <var>
to enclose the names of two variables.
结果
¥Result
技术总结
规范
Specification |
---|
HTML Standard # the-var-element |
浏览器兼容性
BCD tables only load in the browser
¥Browser compatibility