CSS structure pseudo Class E: first-child/last-child/only-child/empty,

Source: Internet
Author: User

CSS structure pseudo Class E: first-child/last-child/only-child/empty,

E: first-child explanation: the first child element of E's parent element is exactly E. Define the style for E.

E: last-child explanation: the last sub-element of the parent element of E is exactly E. Define the style for this E.

E: only-child explanation: the parent element of E has only one child element. This is exactly E. Define the style for this E.

E: empty explanation: the E element does not have child elements or text content. Define a style for this E element.

 

 

Example: as long as the Eelement is the first child element of its parent. It must satisfy two conditions at the same time. One is "first child element" and the other is "This child element is exactly E ".

<Style> span: first-child {color: red;} p: first-child {color: blue ;} /* The first child element of the parent element of the p element is div rather than p, so this style does not work */I: first-child {color: orange ;} </style> <div class = "demo"> <div>. the first child element of demo is div </div> <! -- The First span element is the first span of its parent P element, the color turns red --> <p> <span> the first span </span> the first paragraph P <span> the second span </span> </p> <! -- The first I element is the first I of its parent a element, color changes to orange --> <p> one link <I> the first I element </I> </p> <! -- The second I element is the first I of its parent a element, color changes to orange --> <p> one link <I> the second I element </I> </p> <p> one link </p> </div>

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.