為帶有 CSS 焦點的元素設定樣式
要選擇具有焦點的元素,請使用:focus 選擇器。您可以嘗試執行以下程式碼來實現:focus 選擇器 −
示例
<!DOCTYPE html> <html> <head> <style> input:focus { background-color: green; } </style> </head> <body> <form action = ""> Subject <input type = "text" name = "subject"><br> Student: <input type = "text" name = "student"><br> Age: <input type = "number" name" = age><br> <input type = "submit" value="Submit"> </form> </body> </html>
廣告