CSS selectors-common collection

Source: Internet
Author: User

Tag Selector:

div{

font-size=10px;

color=red;

Background-color=yello;

width=200px;

height=200px;

}

<div> front-end Martial </div>

---------------------------------------

Class selector:

. box{

}

<p class= ' box ' > Ah ah ah </p>

------------------------------------------

ID selector:

#box {

}

<p id= "box" > Ah ah <p>

-------------------------------------------

Wildcard Selector

*{

}

<div>aa</div>

<p>aaa</p>

---------------------------------

Composite selector: Two or more two selectors are connected in different ways.

div.box{//no spaces

color:red;

}

<div class= "box" > Hey </div>//the box in this div turns red

<p class= "box" >aaa<p>

<div>aaaaaa</div>

-------------------------------

Descendant selector: There is a space unlimited generational

Selector + space + selector ..... {

}

. Box san{

cocor:red;

}

<div class= "box" >

<p><span class= "Miss" >aa</span></p>

</div>

----------------------------------

Descendant selector:

div>span{

color;red;

}

<div>

<p><span></span></p>//Here's span is grandson here is P>span

<span></span>//Direct sub-label change that's it.

------------------------------------------------------------------------

The set selector:

div,p,span{

font-size:100px;

}

<div>aaa</div>

<p>aaa</p>

<span>aaaa</span>

------------------------------------

Selector Priority:

first, what is the CSS priority level
CSS precedence refers to the order in which CSS styles are parsed in the browser.
Second, CSS precedence rules
One of the more simple ways to remember is to assign different values to different selectors:
The 1.id selector has the highest default priority, with a weight of 100
The weights of the 2.class selector, the property selector, and the pseudo-class selector are 10
3. The label selector has a lower priority, with a weight value of 1
So when comparing the priority of a style, simply count the number of IDs, class, tag names in the selector and add the corresponding weights. Depending on the results, priority levels can be drawn.
1. Higher priority for results
2. The result is the same, the later defined style has higher precedence
3. If the style value contains!important, the value has the highest precedence

CSS selectors-common collection

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.