input:required{
background-color:#f00;
}
input:required label{
color: #FF3434;
}
I have the above CSS code currently for my form,
I want to be able to make the label red when the field is required. My input field is:
<label for="frmComTelephone">Telephone</label>
<input type="number" name="Telephone" id="frmComTelephone"/>
<label for="frmIn1IncinTime">Time</label>
<input type="text" name="Incident Time" id="frmIn1IncinTime" required="required"/><br>
But that CSS isn’t working how do I solve this?
2ND problem is I have the following CSS:
input:focus
{
background-color:yellow;
}
input[type="text"], input[type="date"],input[type="time"],input[type="number"],textarea,select
{
border-radius:5px;
border-width: 1px;
border-style: solid;
border-color: #C6C6C6;
height:41px;
background-color: #FF3434;
width: 100%;
}
But when the item is focused it doesn’t change to yellow, if i remove “background-color: #FF3434;” it turns yellow on focus?
Is what I am doing not able to be done? Or am I going about this wrong?
Thanks
Issue 1:
This won’t work because the
labelis not a child of theinput. They’re siblings. To solve that you have to create a class and attach it to your label:Issue 2:
Try this:
…
UPDATE
If you’re more comfortable without using
!importantthen try this:OR
if you have an
idon your form this will also work