I'm Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with HTML, CSS and SVG. To receive more information, including news, updates, and tips, you should follow me on Twitter or add me on Google+.

my books

Pro CSS3 Animation book coverPro CSS3 Animation, Apress, 2013

my other blogs

Massive Head CanonMassive Head Canon: Intelligent discussion of movies, books, games, and technology.

my projects

The New DefaultsThe New Defaults — A Sass color keyword system for designers.

CSSslidyCSSslidy — an auto-generated #RWD image slider. 3.8K of JS, no JQuery.

Reversing CSS Rules: Declaration Negation With :not

Undoing style sheet rules with CSS3.

Crafting exceptions to CSS rules has always been fairly straightforward with the use of classes, inheritance, and other selectors. For instance, given a general rule for links:

…if we wanted particular links, which could appear multiple times on our web pages (but did not represent the majority of link content), to appear differently, we could create a class:

Things get more complicated if we add a :hover state to our links:

As it uses a general selector, this rule would apply to all links when the mouse hovers over them, including our special highlighted class. Under traditional CSS, if we wanted to have a different hover effect for our highlighted links, we would have to write another declaration:

For a simple example like this, creation of exceptions is easy; obviously, the more special cases we have, the more negation of general CSS rules we would have to write to cover certain circumstances.

CSS3 provides another option: the :not pseudo-selector. :not allows you to say "the following CSS applies to all affected elements expect the following." Using our simple example above, if we wanted to affect the hover state of all links except those with a .highlighted class, we could write the following:

A better example might be the following: you have a form that contains a series of inputs. You want all inputs that are not text inputs to have a red background. The CSS to achieve this would be the following:

As a CSS3 selector, :not is supported in all modern browsers, including IE9 and higher.

This site helps millions of visitors while remaining ad-free. For less than the price of a cup of coffee, you can help pay for bandwidth and server costs while encouraging further articles.