樣式沒有 “required” 屬性的元素和 CSS
使用 CSS 中的 :optional 選擇器,為沒有 “required” 屬性的 <input> 元素設定樣式。
示例
可以嘗試執行下列程式碼,以實現 :optional 選擇器
<!DOCTYPE html> <html> <head> <style> input:optional { background-color: blue; } </style> </head> <body> <form> Subject: <input type = "text" name = "subject"><br> Student: <input type = "text" name = "student" required><br> </form> </body> </html>
廣告