Tell us what’s happening:
I can’t make the input’s background color turn red only when the element is invalid. Instead it is red all the time and not yellow(the intended colour)
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Job Application Form</title>
</head>
<body>
<div class="container">
<form>
<fieldset>
<legend>yer name:</legend>
<input type="text" id="name" required>
</fieldset>
<fieldset>
<legend>yer email:</legend>
<input type="email" id="email" required>
</fieldset>
<fieldset>
<legend>select what you want:</legend>
<select id="position">
<option>administrator </option>
<option selected>player</option>
<option>member</option>
</select>
</fieldset>
<fieldset class="radio-group">
<legend>how long can you work:</legend>
<label for="full-time">full time<label>
<input type="radio" id="full-time" name="availability" checked>
<label for="part-time">part time<label>
<input type="radio" name="availability" id="part-time">
<label for="intern">intern<label>
<input type="radio" name="availability" id="intern">
</fieldset>
<fieldset>
<legend>what are your (other) comments? </legend>
<textarea id="message"cols="20" rows="5" placeholder="type something.."required></textarea>
</fieldset>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
/* file: styles.css */
input, select, textarea {
background-color:yellow;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
input:focus, textarea:focus {
background-color: black !important;
color: white;
border-color: grey;
outline: none;
}
input:valid, select:valid, textarea:valid {
background-color: green;
}
input:invalid, select:invalid, textarea:invalid {
background-color: red;
}
button:hover {
background-color: pink;
}
.radio-group input[type="radio"]:checked {
background-color: yellow;
border: 2px solid green; /* Corrected here */
box-shadow: 2px 3px red;
color: yellow;
}
input:nth-child(1) {
border-radius: 20px;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Challenge Information:
Build a Job Application Form - Build a Job Application Form