使用 CSS 在導航欄中設定當前連結樣式
如要在導航欄中為當前連結設定樣式,請將樣式新增到 .active。你可以嘗試執行以下程式碼為當前連結設定樣式
例項
<!DOCTYPE html> <html> <head> <style> ul { list-style-type: none; margin: 5; padding: 5; } li a { display: block; width: 70px; background-color: #F0E7E7; } .active { background-color: #4CAF50; color: white; } </style> </head> <body> <ul> <li><a href="#home">Home</a></li> <li><a href="#company" class="active">Company</a></li> <li><a href="#product">Product</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </body> </html>
廣告