CSS selector and css selector priority

Source: Internet
Author: User

CSS selector and css selector priority

  • Summary:
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 ;}...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.