I have:
<label for="modalProblemLocator">
<span>Locator</span>
<span>xxx</span>
</label>
<label for="modalProblemLocator">
<span>Locator</span>
</label>
If there are two <span>
elements inside I would like the second to be red. Is there a way I can specify a selector for the 2nd <span>
only?
What I tried was:
.inputWithLabel {
& > label span:last-child {
color: @alertColor;
}
}
But this does not work if there is just one <span>
, as then the first and only <span>
will also be the last.
Use the nth-child in css
span{
font-size: 30px;
display: block;
}
label span{
color: blue;
}
label span:nth-child(2){
color: red;
}
<label for="modalProblemLocator">
<span>Locator</span>
<span>xxx</span>
</label>
<br><br><br><br>
<label for="modalProblemLocator">
<span>Locator</span>
</label>
<br><br><br><br>
<label for="modalProblemLocator">
<span>Locator</span>
<span>second</span>
<span>third</span>
<span>yyy</span>
<span>xxx</span>
</label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With