CSS Common Selector

Source: Internet
Author: User

"CSS Common selector"

Tag Selector
Syntax: HTML tag name {}
Role: You can select all HTML tags that have the same name as the selector in the page.

li{
color:red;
font-size:24px;
}

class selector (classes selector)
Syntax:. Class Name {}
Call: Use class= "class name" to invoke selector on a label that needs to invoke a selector style
Priority: > Tag Selector

. first{
Color:blue;
}


ID Selector
notation: #ID名 {}
Call: A tag that needs to call a style, starting with a id= "ID name"
Priority: ID Selector >class Selector
Note: The same ID cannot appear on a page

#one {
Background-color:yellow;
Color:green;
}

【the difference between the class selector and the ID selector】
1. Different wording: class selector. Declaration, ID Selector # declaration;
2. Different priority: ID selector >class Selector
3, the scope of the different: class selector can be called multiple times, the ID selector can only be used once.


【naming conventions for selectors】
1, can only have letters, numbers, underscores, minus the composition;
2, the beginning can not be a number. It can't be just a minus sign.

In general, naming requires semantics, using English words and numbers.



Universal Selector
notation: *{}
Function: You can select all the HTML tags in the page.
Priority: Lowest!!!

*{
Color:orange;
}


and set selector
notation: selector 1, selector 2,......, selector n{}
Effective rules: Multiple selectors take the set, as long as the label satisfies any one of the selectors, the style can take effect.

li,.first{
color:red;
}

intersection selector
Wording: Selector 1 selector 2 ... Selector n{} All selectors are next to each other, no separation
Effective rule: Multiple selectors intersect, you must meet the requirements of all selectors in order to take effect

li.first{
color:red;
}

descendant Selector
Wording: Selector 1 selector 2 ... Selector n{} selectors space-delimited
Effective rule: As long as satisfied, the latter selector is the descendant of the previous selector, can be effective. (descendants include descendants, grandchildren, great-grandchild ...) )

Popular speaking: As long as the latter a selector, in the previous selector can be.

Div span{
}

descendant Selector
notation: selector 1> selector 2>......> selector n{} selector with > delimited
Effective rule: must be satisfied, the latter selector is a direct descendant of the previous selector, in order to take effect. (No labels can be spaced in the middle)

div>span{
color:orangered;
}

CSS Common 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.