Workspace
  • Study Book
  • WEB Network HTTP etc
    • Performance Optimization
    • Performance Optimization
    • HTTP/2 & SPDY
    • WebSocket
    • HTTP Header
    • Cross-Origin Resource Sharing
    • JSON, XML, other format
  • Javascript
    • Promise
    • make API call
    • Web API
    • Common JS
    • AJAX
    • Event DOM and delegation
    • ES6 new features
    • special function
    • function API
  • React
    • class component
    • Example
    • Lifting functions/ state up
    • Hot Loader
    • Testing
    • New Features
    • Hook
    • Simple code
    • Life Cycle
  • CSS
    • Horizontal & Vertical Align
    • GPU Animation
    • transform-function
    • LVHA Pseudo-classes
    • Selector
    • How To CSS
  • HTML
  • Redux
  • NodeJS
    • File System
  • express
    • express questions
    • express mongodb
  • Restful API
  • MongoDB
  • Compare
  • Test
    • Jest
  • Deploy development
  • coding question
  • DevOps
  • Webpack
  • GraphQL
Powered by GitBook
On this page
  • Specificity
  • inherits from its ancestor < Directly targeted elements . all the time
  • Specificity Rules

Was this helpful?

  1. CSS

Selector

PreviousLVHA Pseudo-classesNextHow To CSS

Last updated 4 years ago

Was this helpful?

:first-child

The :checked selector matches every checked <input> element (only for radio buttons and checkboxes) and <option> element.

The :root selector matches the document's root element. In HTML, the root element is always the html element.

Specificity

inherits from its ancestor < Directly targeted elements . all the time

<span style="color:red;">

#text{color:red;}

.text{color:red;} [type="text"]{color:red}

span{color:red;}

x,0,0,0

0,x,0,0

0,0,x,0

0,0,0,x

!important 10000

  1. Type selectors (e.g., h1) and pseudo-elements (e.g., ::before).

  2. Class selectors (e.g., .example), attributes selectors (e.g., [type="radio"]) and pseudo-classes (e.g., :hover).

  3. ID selectors (e.g., #example).

  • 继承不如指定

  • !important > 内联 > ID > Class|属性|伪类 Pseudo-classes | Pseudo-elements> 元素选择器

  • :link、:visited、:hover、:active按照LVHA(LoVe HAte)顺序定义

Specificity Rules

  • Equal specificity: the latest rule counts

  • ID selectors have a higher specificity than attribute selectors

  • Contextual selectors are more specific than a single element selector

  • A class selector beats any number of element selectors

  • The universal selector and inherited values have a specificity of 0

inline style > ID selector > class, attribute and pseudo-class selector > tag and pseudo-element selector