- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
CSS Selector to Select Elements Not Having Certain Class / Attribute / Type
Using the CSS :not() pseudo-class, we can refine our styling by selecting those elements which do not have a specific value or does not match a selector.
Example
The following examples illustrate CSS :not pseudo-class.
<!DOCTYPE html> <html> <head> <style> p { background-color: cornflowerblue; color: white; } p:not(div>p) { background-color: khaki; font-size: 1.4em; font-style: italic; color: blue; } </style> </head> <body> <div> <p>Curabitur sapien diam, imperdiet ut est sed, blandit blandit velit. Nunc viverra nunc id ligula ultricies, a fringilla lacus interdum. <span>Sed vel diam at magna pellentesque porttitor.</span> </p> <h3>Demo</h3> </div> <p> Ut rutrum sapien sit amet sapien lacinia, at ullamcorper felis lobortis. Praesent dignissim vel turpis nec ultricies.</p> </body> </html>
Output
This will produce the following result −
Example
<!DOCTYPE html> <html> <head> <style> div { margin: 2%; background-color: cadetblue; padding: 10%; height: 80px; } div:not(.parent) { box-shadow: inset 0 0 24px tomato; padding: 2%; } .parent{ border: 4px ridge orange; } .one { background-color: lightgreen; border: 4px groove gray; } .two{ height: 20px; } </style> </head> <body> <div class="parent"> <div class="one"> <div class="two"></div> <div class="two"></div> </div> <div class="one"></div> </div> </body> </html>
Output
This will produce the following result −
- Related Articles
- How to select elements with a specified attribute with CSS
- Usage of CSS [attribute] Selector
- Role of CSS :not (selector) Selector
- Role of CSS [attribute="value"] Selector
- How to combine a class selector and an attribute selector with jQuery?
- Element Type Selector in CSS
- How to select elements with a specified attribute and value with CSS
- Select elements whose attribute value contains a specified value with CSS
- Select elements whose attribute value ends with a specified value with CSS
- Select elements whose attribute value begins with a specified value with CSS
- How to select elements with an attribute value containing a specified word with CSS?
- Role of CSS :first-of-type Selector
- Role of CSS :last-of-type Selector
- Role of CSS :only-of-type Selector
- Select elements with the specified attribute starting with the specified value with CSS

Advertisements