CSS pseudo-class selector and CSS pseudo-class selector

Source: Internet
Author: User

CSS pseudo-class selector and CSS pseudo-class selector

# CSS pseudo-class selector


# Notes for using the css pseudo-class selector

When using the pseudo-class selector of css to select an element, pay special attention to ''': first-child ''' and ''': nth-child (n),
Web page rendering is read from the end of the statement, that is, a pseudo-class selector like '''p: first-child, it refers to "the item where a certain element uses p as the first subitem", rather than "the first subitem of p", because, in fact, before p, the characters xxx & nbsp; are omitted, which leads to misunderstanding.

E.g.

Div p: first-child {color: red ;}

<Div>

& Lt; h1 & gt; 111 & lt;/h1 & gt;

<P> 222 </p>

<P> 333 </p>

</Div>


The 222 character here will not become red, because it is not the element of the div element whose p element is the first subitem. In this example, the div element uses the p element as the first subitem, and no element meets this condition. The h1 element does not respond to the color: red.


# How to remove the last element with a border using the css pseudo-class selector

If there is a vertical line between each element when designing a navigation bar, the pseudo-class selector can easily remove the right frame line of the last li element.

Li {
Border-right: 1px red solid;
}
Ul li: last-child {
Border-right: none;
}

You can remove the rightmost, that is, the last li with a border line, without the need to name the last li.

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.