<code>:行内代码元素
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Please take two minutes to fill out our short survey.
尝试一下
<p>
The <code>push()</code> method adds one or more elements to the end of an
array and returns the new length of the array.
</p>
code {
background-color: #eee;
border-radius: 3px;
font-family: courier, monospace;
padding: 0 3px;
}
属性
此元素仅包含全局属性。
示例
这是一段包含 <code>
的文字:
html
<p>
函数
<code>selectAll()</code>
将高亮显示输入字段中的所有文本,以便用户可以复制或删除文本。
</p>
结果
备注
要表示多行代码,可在 <pre>
元素中封装 <code>
元素。<code>
元素本身只能表示一段代码短语或一行代码。
可为 code
选择器定义 CSS 规则,以覆盖浏览器的默认字体。用户设置的首选项可能优先于指定的 CSS。
技术概要
内容分类 | 流式内容、短语内容、可感知内容。 |
---|---|
允许的内容 | 短语内容。 |
标签省略 | 不允许,开始标签和结束标签都不能省略。 |
允许的父元素 | 任何接受短语内容的元素。 |
隐含的 ARIA 角色 |
code
|
允许的 ARIA 角色 | 任何 |
DOM 接口 |
HTMLElement ,在 Gecko 1.9.2(包括 Firefox 4)版本之前,Firefox 为该元素实现了 HTMLSpanElement 接口。
|
规范
Specification |
---|
HTML # the-code-element |