Talk about several selectors in CSS

Source: Internet
Author: User
today this article mainly and we talk about several selectors in CSS, the need for friends can refer to, hope to help everyone.

1. Wildcard Selector

The wildcard selector is represented by the "*" symbol, which is the widest range of all selectors and matches all elements of the page.

/* Set the color of all labels in the current page to be red */* {color:red;}

2. Tag Selector

A tag Selector is a label that selects the same name on the current page

/* Set the text color of all P tags to red */p {color:red;}

3. ID selector

The ID selector is identified with "#" followed by the ID name

{:;}

This is the title

Note that the attribute value of an ID in an HTML tag must be unique on a page (it is a specification rather than a hard rule).

ID selector naming specification

    • Allows only letters (case-insensitive, strictly differentiated), Underline, number, that is, id= "head" and id= "head" do not conflict

    • Only allow to start with a letter

    • Name No length limit, can be 1 letters, can be many, but not too long

    • Do not allow label names (not mandatory)

4. Class Selector

A class selector is a type of label that selects the same class attribute value for all labels on a page, with a. (dot) representation

{:;}

This is Heading 1.

This is Heading 2.

A label can contain multiple class selectors, separated by a space in the class tag.

. head {color:blue;}. subhead {font-size:50px;}

This is Heading 2.

5. Composite selector

5.1. Intersection Selector

The intersection selector, also known as a label-specific selector, consists of two selectors, the first of which is a tag selector, the second is a class selector or an ID selector, and no spaces between two selectors, such as

H3.special/  * need to satisfy the tag is H3 also have special class */

Or

P#one/* Need to satisfy the tag is p while ID is one */

5.2. Set selector

The set selector is a comma-connected selector, and any type of selector (including the tag Selector, class selector ID selector, and so on) can be used as part of the set selector. If some selectors define styles that are identical or partially identical, you can use the set selector to define the same CSS style for them

/* Also set the style */h3 for the tag h3 and the Element class box,. box {color:red;font-size:14px;}

5.3. Descendant selector

descendant selectors are used to select the descendants of an element or group of elements, which is written by writing the outer tag in front, the inner tag is written in the back, and the middle is separated by a space. When a tag is nested, the inner tag becomes the descendant of the outer tag (the descendants include not only the son but also the children and grandchildren).

Related Article

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.