此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
<samp>
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
<samp> 元素用于标识计算机程序输出,通常使用浏览器缺省的 monotype 字体(例如 Lucida Console)。
| 内容分类 | Flow content, phrasing content, palpable content. |
|---|---|
| 允许内容 | Phrasing content. |
| 标签省略 | 不允许,开始标签和结束标签都不能省略。 |
| 允许的父级元素 | Any element that accepts phrasing content. |
| DOM 接口 | HTMLElement |
属性
该元素只包含 全局属性。
DOM 接口
该元素实现了 HTMLElement 接口。
备注: 基于 Gecko 1.9.2 及以上,Firefox 还为该元素实现了HTMLSpanElement 接口。
示例
html
<p>Regular text. <samp>This is sample text.</samp> Regular text.</p>
结果
Regular text. This is sample text. Regular text.
规范
| Specification |
|---|
| HTML> # the-samp-element> |
注意
可以使用 CSS 选择器 samp 定义规则来覆盖浏览器的缺省字体。不过,用户设置的偏好可能会优先于指定的 CSS 使用。