Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not CSS selectors

Is there some kind of "not" CSS selector?

For example when I write the following line in my CSS, all input fields inside an tag with class classname will have a red background.

.classname input {   background: red; } 

How do I select all input fields that are OUTSIDE of a tag with class classname?

like image 905
BlaM Avatar asked Apr 07 '09 16:04

BlaM


People also ask

Which is not a CSS selector?

The :not() property in CSS is a negation pseudo class and accepts a simple selector or a selector list as an argument. It matches an element that is not represented by the argument. The passed argument may not contain additional selectors or any pseudo-element selectors.

What is not selector?

Definition and Usage. The :not(selector) selector matches every element that is NOT the specified element/selector. Version: CSS3.

How do I exclude a selector 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.


2 Answers


With current browser CSS support, you can't.

Newer browsers now support it- see Sam's answer for more info.

(See other answers for the alternatives in CSS.)


If doing it in JavaScript/jQuery is acceptable, you can do:

$j(':not(.classname)>input').css({background:'red'}); 
like image 114
Peter Boughton Avatar answered Oct 02 '22 12:10

Peter Boughton


Mozilla supports negation pseudo-class:

:not(.classname) input {background: red;} 

See also: http://developer.mozilla.org/en/Mozilla_CSS_support_chart

like image 24
ultracrepidarian Avatar answered Oct 02 '22 10:10

ultracrepidarian