CSS Selector Summary

Source: Internet
Author: User

CSS code consists of a number of rules, selector + declaration block.

1. Element Selector

Tag name {declaration block},eg:p{font-size:18px;}

All elements that match the tag name will be applied to the rules in the declaration block.

2. Class Selector

. class name {declaration block}

The rules in the declaration block are applied to all the class attributes that are elements of the specified name.

Note: (1), the class name must start with a letter, followed by numbers, letters, hyphens, underscores.

(2), case-sensitive

(3), a class selector can be applied to more than one label.

3. ID Selector

#ID值 {Declaration block}

The attribute ID is the element with the specified value, the rule that declares the block is applied, the ID value is unique, and only one element is selected.

If the class and ID are applied to the same element at the same time, the ID takes effect.

4. Combination Selector

Multiple labels apply the same rule at the same time. eg:h1,h2,h3{color:red;}

5. Pseudo-Class Selector

Element name: Pseudo-class name

Eg:a:link a:visited a:hover a:active

Element name: Nth-child (x)/element name: Nth-of-type (x): the first few elements apply the rule

6. Descendant Selector

Parent element + Space + child element {declaration block}, works for all descendants

7. Subset Selector

Parent element + ">" + child element {declaration block}, only child-level function

8. Attribute Selector

element [attribute name + attribute value]{declaration block}

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

9. Pseudo Element Selector

Element name: before/after {declaration block}, applying the claim block rule before/after the element name

Element name: first-line/first-letter {declaration block}: Sets the style of the first letter or the first line

10. Sibling Selector

Brother Element 1+ Brother element 2 {declaration block}: Select 1 after 2 apply the claim block rule.

CSS Selector Summary

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.