Reputation: 37034
I have the following html structure:
<div class="unit">
<span class="error"></span>
<input type="text" class="textInput"/>
</div>
I add span only if validation restriction is broken.
thus if validation passed I render following html:
<div class="unit">
<input type="text" class="textInput"/>
</div>
Is there way in css to draw red border for input if it has sibling span with class error
.
Upvotes: 0
Views: 157
Reputation: 31
Consider the following code:
.error + input.textInput {
border: 1px solid red;
}
This will select all .textInput nodes which are immediately preceded by a .error node.
Upvotes: 2
Reputation: 17366
You can try adjacent sibling selector
.error + input.textInput
{
border:1px solid red;
}
Upvotes: 5
Reputation: 18099
Try this:
.unit span.error + input.textInput{border:1px solid red;}
or
.unit span.error + input.textInput{outline:1px solid red;}
Upvotes: 1