[CSS] DOM Hierarchy Pseudo classes:first-child:last-child:nth-child (demystified)

Source: Internet
Author: User

DOM hierarchy pseudo-classes allow you to style specific elements based on where they fall in the hierarchy and what type of elements they is. You can also use:nth-child to target custom element patterns, like every other element.

<!DOCTYPE HTML><HTMLLang= "en"><Head>  <MetaCharSet= "Utf-8">  <title>Gistrun</title>  <Linkrel= "stylesheet"href= "Styles.css">      <style>ul{List-style:None;margin:0;padding:0;        }Li{padding:5px;        }        /*Li:first-child {Background-color:rgb (225, 231, 252);            } li:last-child {Background-color:rgb (225, 231, 252);            } li:nth-child (2) {Background-color:rgb (225, 0, 252); }*/        /*The even child*/        /*Li:nth-child (2n) {background-color:gold; }*/        /*The odd child*/        /*Li:nth-child (2n+1) {background-color:darkred; }*/        /*First 4 children*/li:nth-child (-n+4){Background-color:Cadetblue;        }        /*Expect first three children*/li:nth-child (n+4){Background-color:Lightgoldenrodyellow;        }        /*Other psuedo classes: *: Nth-last-child *: Only-child *: Only-of-type *: Last-of-type *: Nth-of-type (an+b) *: Nth-last-of-type (an+b)*/</style></Head><Body>  <ul>    <Li><ahref="#"Target= "_blank">Target=_blank</a></Li>    <Li><ahref="#"Target= "Someframe">Target=someframe</a></Li>    <Li><ahref="#"rel= "Link-blog">Rel=link-blog</a></Li>    <Li><ahref="#"rel= "Linkproducts">Rel=linkproducts</a></Li>    <Li><ahref="#"rel= "link about">Rel=link about</a></Li>    <Li><ahref="#"rel= "Link-about"title= "Special">Rel=link-about title=special</a></Li>    <Li><ahref="#"rel= "Link-other"title= "Special">Rel=link-other title=special</a></Li>    <Li><ahref="#"rel= "This item available now">Rel=this Item Available NOW</a></Li>    <Li><ahref="#"rel= "Product-200-available-now">Rel=product-200-available-now</a></Li>    <Li><ahref="#"rel= "linkproductavailable300">rel=linkproductavailable300</a>    <Li><ahref="#"rel= "sale-product-400">rel=sale-product-400</a></Li>    <Li><ahref="#"rel= "Sale">Rel=sale</a></Li>    <Li><ahref="#"rel= "product-500-discontinued">rel=product-500-discontinued</a></Li>    <Li><ahref="#"rel= "product600discontinued">rel=product600discontinued</a></Li>    <Li><ahref="#"rel= "Discontinued">rel=discontinued</a></Li></ul>  <Scriptsrc= "Script.js"></Script></Body></HTML>

[CSS] DOM Hierarchy Pseudo classes:first-child:last-child:nth-child (demystified)

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.