Reputation: 23
I have the class "item" appearing throughout the page. The styling is the same throughout the page. However, I don't want the styling to be applied when it appears in an element with the class "group". I'd really like to use the :not pseudo selector so I don't have to create another style for this special case.
CSS
.item, .group div:not(.item){
color:red;
}
HTML
<div class="item">I have style!</div>
<div class="group">
<div class="item">No style for me, thanks!</div>
</div>
Upvotes: 2
Views: 2845
Reputation: 5418
This isn't a perfect solution, but you could target the .group
div and say something like:
div:not(.group) .item {
color: red;
}
Here's a fiddle to play with it: http://jsfiddle.net/jqxgetsj/
The only constraint is that you have to have direct parent selectors or something rather targeted.
Upvotes: 1
Reputation: 4432
Theres no parent selector in CSS, so you can't go inside out. Theres a child selector though, which can be used great in your example:
body > .item {
color:red;
}
<div class="item">I have style!</div>
<div class="group">
<div class="item">No style for me, thanks!</div>
</div>
Upvotes: 0