How to exclude particular class name from CSS selector ?
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.
Syntax:
:not(element) {
// CSS Property
}
Example:
<!DOCTYPE html> <html> <head> <title> How to exclude particular class name from CSS selector ? </title> <meta charset="utf-8"> <meta name="viewport" content= "width=device-width, initial-scale=1"> <link rel="stylesheet" href= <style> h1, h3 { text-align: center; } .todo { color: gray; } /* Style to all li element except todo class name */ li:not(.todo) { text-decoration: line-through; color: green; } </style> </head> <body> <div class="container"> <h1 class="text-success"> GeeksforGeeks </h1> <hr/> <h3>To-Do List:</h3> <ul class="list-group"> <li class="list-group-item"> Complete The Online Course </li> <li class="list-group-item"> Goto Kolkata On Wednesday </li> <li class="todo list-group-item"> Write Another Article For GeeksforGeeks </li> <li class="todo list-group-item"> Complete Java Assignment </li> <li class="todo list-group-item"> Buy Books On JavaScript </li> </ul> </div> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- CSS | Class Selector
- jQuery | .class Selector
- Not class selector in jQuery
- How to find the parent class name with known class in jQuery ?
- How to override the CSS properties of a class using another CSS class ?
- CSS | #id Selector
- CSS | * Selector
- CSS | ::after Selector
- CSS | ::before selector
- CSS | :not Selector
- CSS | :root Selector
- CSS | :checked Selector
- What does the “+” (plus sign) CSS selector mean?
- jQuery | :contains() Selector
- CSS | [attribute$=value] Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



