YogeshChauhan . com

Specificity of attribute selectors

in CSS on August 23, 2020

Attribute selectors have specificity same as class selector and pseudo class.

0-1-0

Here is W3's guide on Calculating a selector’s specificity: w3.org

Quoting W3 guide here,

A selector’s specificity is calculated for a given element as follows:

count the number of ID selectors in the selector (= A)
count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= B)
count the number of type selectors and pseudo-elements in the selector (= C)
ignore the universal selector

Examples


*[type=radio] // 0-1-0

.class_name input[type="text"] { }  // 0-2-1
amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 7 How to disable right click and drag and drop of images using jQuery? May 7 How to render Lists in React? May 7 What’s the difference between variables in CSS and SCSS (Sass)? May 7 How to define variables in SCSS (Sass)? May 7 How to show and hide an element on click in React? May 5 Use inline if to make a shorter conditional syntax in React

You might also like these

Object destructuring in JavaScript: Unpacking fields from objects passed as function parameterJavaScriptHow to add a Bar Chart in Angular App?AngularWhat does it mean by Continuous Integration, Continuous Delivery and Continuous Deployment?MiscAll possible ways you can Insert Data in PostgresPostgresHow to control file extensions with an .htaccess file?MiscHow to get the height and width of an element using JavaScript?JavaScriptHAVING Clause in Postgres with Examples in All Aggregate FunctionsPostgresHow to add multiple Columns in CSS like Bootstrap?CSSAll different methods for accessing elements in the DOM using JavaScriptJavaScriptHow to Hide HTML elements automatically after few seconds using JavaScript?HTMLHow to check if radio button is checked or not using JavaScript?JavaScriptRBV Framework and closing of big brandsMisc