CSS Base 2--Selector

Source: Internet
Author: User

I've said the style rule before, and I know the style rule syntax is: selector + declaration block

such as: div{color:black;padding:10px;} The DIV represents the selector (here is the element selector), and the content in the curly braces is the declaration block.

Selector Selector used to specify which or which elements of a style rule can be used in an HTML document. There are several common selector types:

1. Element selector (type selector) : Any HTML element on the page that matches the selector, regardless of the position of those elements in the document tree.

such as: p{Background:aqua; color:pink;} Matches any P element on a Web page, regardless of the position of the P element in the document tree

2. Class selector: is used to select any HTML element that has a class attribute, in the form of syntax:. Class Name {property: value;}

The same class property value can appear multiple times on the same page

3.ID Selector:is used to select any HTML element that has an id attribute, in the form of syntax: #id名 {property: value;}
the same id attribute value can only appear once on the same page

4. Wildcard selector: used to select all elements, Syntax :*{property: value}
5. Include selector : A descendant element that is used to select an element of a document

The first method:

The second method of

6. Pseudo-Class selector:four different states for formatting hyperlinks <a> elements in different ways
A: link{}selectors used in the not-visited link

a:visited{} The selector used in the link that has been visited

a:hover{} A selector for the link on which the mouse cursor is placed, where hover can also be used in other elements to make edits to the style that the mouse cursor places on the target

a:active{} A selector on a link that gets focus (for example, clicked)

7. pseudo element Selector :

(1): First-line The selector for the first row of an element

such as the first line of a paragraph

Only Hello is red.

(2): First-letter The selector for the first character of an element

such as the first character of a paragraph

OnlyMoThe word is red.

(3): First-child for <body> The first is a selector (: first-child) for all contents of the preceding element

suddenly look backIt's red.

The color of no font content is red,because the first element in <body> is a div, not p

The priority of the selector
: ID Selector > class selector > Pseudo class selector > element/pseudo element selector > wildcard Selector




CSS Base 2--Selector

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.