I have css declaration like this
#first, #second, #third {
font-size:1em;
background: url('path/to/image') no-repeat;
}
Next I want to remove background only for #third;
I have tried
#third {
background:none;
}
But it doesn`t work.
Your first selector is more specific than the second one, so it has priority.
To solve this, you can make the second selector equally specific by changing it to #second #third.
If that won't select the same elements, your design is flawed; element IDs should be unique.
Alternatively, you can add !important to the second background rule to force it to override the first one.
Why not just do this?
#first, #second {
font-size:1em;
background: url('path/to/image') no-repeat;
}
#third {
font-size:1em;
}
#first, #second, #third if not, I agree with youIt's not working because #second #third is more specific than #third. Did you mean to group #second and #third together, or did you forget a comma?
It sounds like that wasn't what you intended, so this should fix it:
#first, #second, #third {
font-size:1em;
background: url('path/to/image') no-repeat;
}
Note the comma - that's all it takes. Your #second element should also be styled correctly with this edit.
Also, did you place the separate declaration for #third after the other set of code? Order matters, and it would need to come after the declaration of #first, #second and #third.
#first, #second #third. Are you sure you don't mean#first, #second, #third, with the extra comma?