要为所有<input>元素设置无效值的样式,请使用CSS:invalid选择器。
您可以尝试运行以下代码来实现:invalid选择器-
<!DOCTYPE html> <html> <head> <style> input:invalid { background: red; } </style> </head> <body> <h2>Heading</h2> <input type = "email" value = "InvalidEmail"> <p>The style (red color background) appears if you type an irrelevant/ invalid email address.</p> </body> </html>