CSS selector and css selector priority
In html, the selector is used to locate elements on the page. The browser uses different methods to find elements for different types of selectors. The core selectors are shown in the following table (they are also the most widely used selectors ):
- Summary of multiple selector types:
Generally, an element (simple selector) is selected based on the id and class attributes ). In addition to this situation, the following selector methods are available:
① Attribute Selector
The sample code is as follows :... [lang] {background-color: gray; color: # ffffff;} [lang $ = "s"] {font-size: 14px ;}...... <body>
② Relationship Selector
The sample code is as follows:... h1 ~ [Lang] {background-color: gray; color: # ffffff ;}......
③ Pseudo element and pseudo class selector
The sample code is as follows :... p: first-letter {font-size: x-large; color: red;}: nth-of-type (2) {background-color: red; color: #000000 ;}...
④ Combined selector and anti-Selector
Use selector combinations to achieve joint selection and inverse selection.
The sample code is as follows :... h1, h2 {background-color: red; color: #000000 ;}: not (html): not (body): not (: first-child) {border: medium double #000000 ;}...