如何在 HTML 中使用 標記對鍵盤輸入進行格式化?
我們使用 <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>
廣告