How to deselect with CSS?

2019-04-11 14:33发布

问题:

i would like to deselect and #id item from a selection without changing HTML or adding any classname,

lets say i want to emulate this Jquery sentence in CSS

 $('img').not('#thisone').CSS();

is it possible?

回答1:

Use CSS3's :not() selector (which has an equivalent jQuery selector):

img:not(#thisone) {
}

If you need better browser support, there's always the fact that ID selectors, being the most specific simple selectors, are good for overrides:

img {
    /* All images */
}

#thisone {
    /* Revert styles for this particular image */
}


回答2:

Check out this post on the :not selector in CSS3



回答3:

This might help http://www.w3.org/TR/css3-selectors/#negation

(Jquery does that internally anyway, I think, didn't check, though).