Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a CSS formatting? [duplicate]

Tags:

css

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.

like image 977
Joe Huang Avatar asked Jul 05 '11 16:07

Joe Huang


People also ask

How do you exclude a style in CSS?

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.

What is not in CSS?

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.


1 Answers

You have two options:

  1. You can explicitly override all of the styling defined in .div1 img with what they should be in .myimg
  2. You can write .div1 img:not(.myimg) for the first rule.
like image 53
rockerest Avatar answered Oct 04 '22 15:10

rockerest