HTML键盘输入元素(<kbd>) 用于表示用户输入,它将产生一个行内元素,以浏览器的默认monospace字体显示。
Content categories | Flow content, phrasing content, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | {{no_tag_omission}} |
Permitted parent elements | Any element that accepts phrasing content. |
DOM interface | {{domxref("HTMLElement")}} Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the interface {{domxref("HTMLSpanElement")}} for this element. |
该元素仅支持全局属性.
<p>Type the following in the Run dialog: <kbd>cmd</kbd><br />Then click the OK button.</p> <p>Save the document by pressing <kbd>Ctrl</kbd> + <kbd>S</kbd></p>
Type the following in the Run dialog: cmd
Then click the OK button.
Save the document by pressing Ctrl + S
此显示效果为 MDN 特殊显示效果,无法更改。具体显示效果请自行测试。
通过定义CSS规则可以改变kbd的默认字体。用户首选项设置可能会比该CSS规则具有更高优先级。
当<kbd>元素处于<samp>元素之中时,它代表着被系统回显的输入。
当<kbd>元素中包含<samp>元素时,该输入是基于系统输出的,比如调用某个菜单项。
当<kbd>元素处于另一个<kbd>元素之中时,它代表了一个实际的按键,或是该输入机制下的某个单位输入。
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-kbd-element', '<kbd>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-kbd-element', '<kbd>')}} | {{Spec2('HTML5 W3C')}} | Expanded to include any user input, like voice input and individual keystrokes. |
{{SpecName('HTML4.01', 'struct/text.html#h-9.2.1', '<kbd>')}} | {{Spec2('HTML4.01')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |