Reputation: 26054
I have two classes, one is used specifically fro certain tags, the other can be used on any tag:
a.action_link_2 {
display:inline-block;
}
.display_none {
display:none;
}
In some circumstances I want to apply both these styles and have tried this:
<a class="action_link display_none">content</a>
However, when rendered in the browser, the 'action_link' class take precedence. I understand that this might be to do with CSS class priority, i.e. tag-specific classes taking precedence. My question is how do I make this tag hidden using these classes and still allow the 'display_none' class to be used on any element to hide it?
Upvotes: 2
Views: 229
Reputation: 10440
you could just remove the a
from before the class, and also add body before the display none class to give it a higher priority.
.action_link_2 {
display:inline-block;
}
body .display_none {
display:none;
}
Upvotes: 3
Reputation: 15715
You are right, it because specificity read this
To overcome the problem, you need to increase the specificity for
.display_none
class when it is present on action_link_2 .
Just add one more rule, just below all of it
a.display_none {
display:none;
}
This will work , but there will be a problem when you try to add class
.display_none
to ananchor
, but there is no.action_link_2
class present.
So the final and best solution would be to use:
.action_link_2.display_none {
display:none;
}
Upvotes: 2