Introduction to Css selectors and pseudo classes added to HTML5

Source: Internet
Author: User

Comments: HTML5 has added Css selectors and pseudo classes. This article has summarized some of them and provided a brief introduction. If you like html5, you can refer to them and hope to help you with the selector.
P [name ^ = "my"] {font-size: 14px}
Selector ^ = indicates that the rule is applied to <p> element labels starting with "my" for all name attributes.
P [name $ = "my"] {font-size: 14px}
Selector $ = indicates that the rule is applied to the <p> element label ending with "my" for all name attributes.
P [name * = "my"] {font-size: 14px}
Selector $ = lecture rules applied to all <p> elements whose name attributes contain "my"
Selector>, + ,~
Selector> indicates that the affected element is the child element of the first element.
Selector + This selector references the element following the element. The two elements must have the same parent level.
Selector ~ Similar to +, the affected elements do not necessarily follow the first element.

":" Must be added between the pseudo class and the referenced element name.
Example: myclass: nth-child (2)
The second element in myclass
Keyword "odd", "even"
Myclass: nth-child (odd): affects the index location of its parent element that is odd
Myclass: nth-child (even): The index location of the parent element is even

The Code is as follows:
<Style>
. Test: nth-child (odd)
{
Color: Blue;
}
. Test: nth-child (even)
{
Color: Red;
}
. Test: nth-child (2)
{
Color: Green;
}
</Style>
<Div class = "test">
<P>
1
</P>
<P>
2
</P>
</Div>
<P class = "test">
1
</P>
<P class = "test">
2
</P>
<P class = "test">
1
</P>
<P class = "test">
2
</P>

The effect is as follows:
1
2
1
2
1
2
Negative pseudo class
: Not (p) {color: red}
All elements except the <p> element are red.

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.