如何在 HTML 中使用 <kbd> 标签进行键盘输入格式化?
htmlweb developmentfront end technology更新于 2024/6/7 6:04:17
我们使用 <kbd> 标签来定义键盘输入。它是一个短语标签,用于标识代表用户键盘输入的文本。大多数浏览器会使用默认的等宽字体显示其中的内容。我们可以使用样式表覆盖该字体。
语法
<kbd> Keyboard text…
示例 1
以下是在 HTML 中使用 <kbd> 标签的示例 -
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="description" content="meta tag in the web document"> <meta name="keywords" content="HTML,CSS"> <meta name="author" content="lokesh"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <p> Open a new file using the keyboard shortcut <kbd>Ctrl</kbd> + <kbd>N</kbd> </p> <p>Press<kbd>Ctrl </kbd> + <kdb>C </kdb>to copy text from the file.</p> <p>Press<kbd>Ctrl </kbd> + <kdb>P </kdb>to paste text to the file.</p> </body> </html>
示例 2
此标签在 HTML 文档中可用作 -
<html> <body> <p>Two special keys in keyboard are:<kbd>ctrl</kbd>, <kbd>alt</kbd>.</p> </body> </html>
示例 3
我们还可以在 HTML 文档中为键盘值添加样式。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="description" content="meta tag in the web document"> <meta name="keywords" content="HTML,CSS"> <meta name="author" content="lokesh"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> kbd { border-radius: 2px; padding: 2px; border: 1px solid black; } </style> </head> <body> <p> Open a new file using the keyboard shortcut <kbd>Ctrl</kbd> + <kbd>N</kbd> </p> <p>Press<kbd>Ctrl </kbd> + <kdb>C </kdb>to copy text from the file.</p> <p>Press<kbd>Ctrl </kbd> + <kdb>P </kdb>to paste text to the file.</p> </body> </html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

