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)