源代碼
點擊運行
<!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.active { background-color: #4CAF50; color: white; } li a:hover:not(.active) { background-color: #555; color: white; } </style> </head> <body> <h2>垂直導航條</h2> <p>在點擊了選項後,我們可以添加 "active" 類來標准哪個選項被選中。</p> <ul> <li><a class="active" href="#home">主頁</a></li> <li><a href="#news">新聞</a></li> <li><a href="#contact">聯系</a></li> <li><a href="#about">關於</a></li> </ul> </body> </html>
運行結果