i add * after a input,
i want select this for change color in input:valid
and invalid
,
but by this CSS not working why?
form::after {
content: "*";
}
#fname:invalid~::after {
background: red;
border-color: yellow;
}
#fname:valid~::after {
background: rgb(3, 183, 168);
border-color: rgb(9, 9, 0);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="/action_page.php" id="frm">
<label for="fname">First name:</label><br>
<input required type="text" id="fname" value=""><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
2
Answers
You can use :has() (supported in Firefox behind the layout.css.has-selector.enabled flag):
Or simply replace
:after
in<form>
with, say,<span>*</span>
:Replace
::after
with span