Reputation: 8805
My HTML element has an attribute and the goal is to give a certain style to this element when found inside another class.
for ex.:
<style>
em {color:#ff0000;}
.emClass {color:#ff0000;}
.pClass em {color:#ff0000;}
.pClass .emClass {color:#ff0000;}
</style>
<p>
Please <em>red</em> me.
</p>
<p>
Please <em class="emClass">red</em> me.
</p>
<p class="pClass">
Please <em>red</em> me.
</p>
<p class="pClass">
Please <span class="emClass">red</span> me.
</p>
<p class="pClass">
Please <em class="emClass">orange</em> me.
</p>
the goal is to have the text in Orange only in case:
(live example: https://jsfiddle.net/Yatko/Ffkcq/ )
Thank you for your help!
Upvotes: 2
Views: 2324
Reputation: 82337
You can prefix the class name with the element type. You should target the specific element like this:
.pClass em.emClass {color:orange;}
.pClass span.emClass {color:red;}
Upvotes: 2
Reputation: 24733
You can do this with CSS DEMO https://jsfiddle.net/kevinPHPkevin/Ffkcq/4/
em {
color:#ff0000;
}
.emClass {
color:#ff0000;
}
.pClass em {
color:#ff0000;
}
.pClass .emClass {
color:#ff0000;
}
.pClass em.emClass {
color: #FAC802;
}
Upvotes: 1