CSS is positioned between sibling elements

Source: Internet
Author: User
CSS is positioned between sibling elements

Note

* 1.css Native Selector is the fastest to find elements

* 2. Custom selector: Start, very similar to Pseudo-class in CSS

* 3. The custom selector is positioned based on the location found with the native selector

* 4. Use native selectors as much as possible to get elements

1.:nth-child (n): CSS is calculated starting from 1

$ (' Ul:nth-child (2) '). CSS (' Color ', ' red ')

2.:nth-child (2n): Select all even position elements (n=[1,2,3,...])

$ (' Ul:nth-child (2n) '). CSS (' Color ', ' red ')

3.:nth-child (2n+1): Select all odd position elements (n=[0,1,2,...])

$ (' Ul:nth-child (2n+1) '). CSS (' Color ', ' red ')

4.:nth-child (even): Gets the even position element; Nth-child (odd): get odd position element

$ (' Ul:nth-child (even) '). CSS (' Color ', ' red ')  //Even behavior Red text $ (' Ul:nth-child (Odd) '). CSS (' color ', ' green ')//odd behavior Green text

5.:nth-last-child (): Reverse calculation position

$ (' Ul:nth-last-child (2) '). CSS (' Color ', ' red ')  ///2nd, or 9th-digit $ (' ul:nth-last-child (even) '). CSS (' Color ', ' red ')  //Reverse start Select even position

6.:first-child: The first child element of a parent element

$ (' Ul:first-child '). CSS (' Color ', ' red ')

7.:last-child: The last child element of the parent element

$ (' Ul:last-child '). CSS (' Color ', ' red ')

8.:only-child: The only child element in the parent element

$ (' Ul:only-child '). CSS (' Color ', ' red ')

9.nth-of-type (), similar to Nth-child (), returning only elements of the same type

<! DOCTYPE html>

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.