The use of Nth-child

Source: Internet
Author: User

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>

All of the following examples are based on the code above.

1: Select all other elements that are not in the child element except the first one

A:ul Li:not (: first-child) {

Background:gray;

}

B:ul li:first-child~*{

Background:gray;

}

Based on the expansion of the first way, we can choose to remove the style of the other elements of any one element

For example I would now like to select other elements in addition to the third element: UL Li:not (: Nth-child (3)) {colro:red}

If you want to choose a style for the first three elements:

UL Li:nth-child (-n+3) {

font-size:30px;

}

Because N is a range, [0, Infinity], and here is-N, so the interval is (infinity, 0], because of n+3, so we choose the range is (infinitesimal, 3], because nth-child from 1 to start retrieving, so chose the three-way

If you want to select the second three elements

UL Li:not (: Nth-child (-n+2)) {

}

The use of Nth-child

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.