The 10 most misleading CSS selectors and css selectors

Source: Internet
Author: User

The 10 most misleading CSS selectors and css selectors

These selectors include first-child, last-child, only-child, nth-child (n), nth-last-child (n) and first-of-type, last-of-type, only-of-type, nth-of-type (n), nth-last-of-type (n ). Among all the selectors, these ten selectors are probably the ones most easily misunderstood.


1. About n

1) The expression of n is xn + y. Such as 1, 2n, 2n + 1.

2) n of the nth-child (n) series numbers all child elements of the parent element; nth-type-child (n) n in only numbers the same type of elements, ignoring other elements in the middle.


II. E: first-child and E: first-child

The two methods mentioned above are not the same. The difference is that there are no spaces before the first-child, and there are no spaces. The difference is great, which is the most common misunderstanding.

1) E: first-child with no space indicates "select such an Eelement, and E is the first child element of its parent element ";

2) E: first-child with spaces indicates "select the first child element of E".


CSS General selector (*), Basic Issues

<Html>
<Head>
<Title> untitled document </title>
<Style type = "text/css">
*{}
# Box {}
# Box. aa {}
</Style>
</Head>
<Body>
<Div id = "box">
<Div class = "aa"> </div>
<Div class = "aa"> </div>
</Div>
</Body>
</Html> This is the correct method. * indicates the global attribute, # banner * {style}
# The common attributes under the banner. The ID is unique and cannot be used repeatedly on the page. The CLASS can be used multiple times.

Class selector in css

This is a special issue in CSS!
You used the selector. XXX {
Color: # ccc;
}
There is no problem at all. If you use the same class for other tags in the HTML document, you just want to apply the style P. XXX {
Color: # ccc;
}
It is important.

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.