I have some divs:
<div class="A">"Target"</div>
<div class="A B">"NotMyTarget"</div>
<div class="A C">"NotMyTarget"</div>
<div class="A D">"NotMyTarget"</div>
<div class="A E">"NotMyTarget"</div>
Is there a CSS selector that will get me the div containing Target but not the divs containing NotMyTarget?
Solution must work on IE7, IE8, Safari, Chrome, and Firefox
Edit: So far Nick is the closest. It’s clumsy and I don’t like the solution, but at least it works:
.A
{
/* style that all divs will take */
}
div.B
{
/* style that will override style .A */
}
You can use the attribute selector to match the
divthat has only one class:If you want to select another
divthat has multiple classes, use quotes:Some browsers do not support the attribute selector syntax. As usual, “some browsers” is a euphemism for IE 6 and older.
See also: http://www.quirksmode.org/css/selector_attribute.html
Full example:
EDIT 2014-02-21: Four years later,
:notis now widely available, though verbose in this specific case:Unfortunately, this doesn’t work in IE 7–8 as specified in the question: http://caniuse.com/#search=:not