CSS Selector

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 Feb 25 13:46
Editor
Edited
Edited
2023 Oct 23 5:43
Refs
Refs

id is fastest & pseudo class is slowest

Selector Performance Rank
  1. id (#myid)
  1. class (.myclass)
  1. tag (div, h1, p)
  1. adjacent sibling (h1 + p)
  1. child (ul > li)
  1. descendent (li a)
  1. universal (*)
  1. attribute (a[rel=”external”])
  1. pseudo-class and pseudo element (a:hover, li:first)
CSS Selectors
 
 
 
 

Learning Game

CSS Diner
You're about to learn CSS Selectors! Selectors are how you pick which element to apply styles to. Exhibit 1 - A CSS Rule p { margin-bottom: 12px; } Here, the "p" is the selector (selects all elements) and applies the margin-bottom style.
CSS Diner

selectors

Selectors Level 3
Selectors are patterns that match against elements in a tree, and as such form one of several technologies that can be used to select nodes in an XML document. Selectors have been optimized for use with HTML and XML, and are designed to be usable in performance-critical code.
Selectors Level 3

text

A way to match on text using CSS locators
Thanks for contributing an answer to Software Quality Assurance & Testing Stack Exchange! Please be sure to answer the question. Provide details and share your research! Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience.
A way to match on text using CSS locators
CSS [attribute~=value] Selector
Select and style elements with a title attribute containing the word "flower": [title~=flower] { background-color: yellow; } Try it Yourself " The [ attribute~= value] selector is used to select elements with an attribute value containing a specified word. The numbers in the table specifies the first browser version that fully supports the selector.
CSS [attribute~=value] Selector
 
 

Recommendations