使用CSS:optional选择器来设置<input>元素的样式,这些元素没有“ required”属性
您可以尝试运行以下代码来实现: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>