Possible Duplicates:
How do I prevent CSS inheritance?
is there a way to exclude a tag from css class
I have CSS like this
.div1 img {
// ...
}
.myimg {
// ...
}
and my HTML code is like this,
<div class="div1">
...
<img src="..." class="myimg"> // image html
...
</div>
The css formatting defined in .div1 img
is obviously applied to the image html code. However, I actually don't want it happen. What can I do to not to have '.div1 img' effects on that image html code? I don't want to modify the content of div1 img
or related html code because it is used in other places already (and it is a template code that I don't want to mess with).
P.S. I cannot remove or modify <div class="div1">
either because there is other template code around.
Thanks.
In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.
The :not() CSS pseudo-class represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.
You have two options:
.div1 img
with what they should be in .myimg
.div1 img:not(.myimg)
for the first rule.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