Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is :not possible on a wildcard attribute selector

Is it possible to use a :not selector on a wildcard attribute selector?

Example:

<div class="circle circle-red"></div>
<div class="circle circle-blue"></div>
<div class="circle circle-yellow"></div>
<div class="circle"></div>

I want to address only the div with class 'circle' and not the divs with class 'circle-red', 'circle-blue', 'circle-yellow'

like image 618
Joop Passchier Avatar asked May 31 '16 11:05

Joop Passchier


People also ask

Which selector is used as a wildcard selector?

The universal selector is used as a wildcard character.

What is the purpose of * wildcard selector in C?

The * wildcard is known as the containing wildcard since it selects elements containing the set value. With the ^ wildcard, you get to select elements whose attribute value starts with the set value. The $ wildcard lets you select elements whose attribute values end with the specified value.

What is a wildcard in HTML?

A wildcard is a symbol that takes the place of an unknown character or set of characters. Commonly used wildcards are the asterisk ( * ) and the question mark ( ? ).


1 Answers

You can use the negation selector (:not) along with the attribute contains selector for this purpose.

The selector div.circle:not([class*="circle-"]) will select only the div which has the circle class but doesn't contain any other class of the format circle-.

div.circle:not([class*="circle-"]) {
  color: green;
}
<div class="circle circle-red">Red</div>
<div class="circle circle-blue">Blue</div>
<div class="circle circle-yellow">Yellow</div>
<div class="circle">None</div>
<div class="circle-orange">Orange</div>
like image 95
Harry Avatar answered Sep 27 '22 20:09

Harry