源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> <style> ul { list-style-type: none; margin: 0; padding: 0; width: 200px; background-color: #f1f1f1; } li a { display: block; color: #000; padding: 8px 16px; text-decoration: none; } /* 鼠標移動到選項上修改背景顏色 */ li a:hover { background-color: #555; color: white; } </style> </head> <body> <ul> <li><a href="#home">主頁</a></li> <li><a href="#news">新聞</a></li> <li><a href="#contact">聯系</a></li> <li><a href="#about">關於</a></li> </ul> <p>背景顏色添加到鏈接中顯示鏈接的區域</p> <p>注意,整個區域是可點擊的鏈接,而不僅僅是文本。</p> </body> </html>
運行結果