Select the third child from list - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Select the third child from list

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
.right {
   background-color:Chartreuse;
}

.right>img {
   background-color:yellow;
}

.right:nth-child(3) {
   background-color:blue;
}
</style> <!-- ww w .j a v a  2 s. c o  m-->
 </head> 
 <body> 
  <div class="parent" style="padding-top:5px;"> 
   <div class="right">
     line 1 
   </div> 
   <div class="right">
     line 2 
   </div> 
   <div class="right"> 
    <img src="https://www.java2s.com/style/demo/Safari.png"> 
   </div> 
   <div class="right">
     line 4 
   </div> 
   <div class="right">
     line 5 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials