With CSS only: Select first occurrence of class throughout whole document - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:class

Description

With CSS only: Select first occurrence of class throughout whole document

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">
div.inner>.copyright {
   display:none;
}

div.inner:first-child .copyright {
   display:block;
   background:Chartreuse;
}
</style> <!-- ww w.  j  a v a 2 s .  com-->
 </head> 
 <body> 
  <div class="outer"> 
   <div class="inner"> 
    <div class="content">
      Lorem 
    </div> 
    <div class="copyright">
      Lorem 
    </div> 
    <!--// DISPLAY THIS ONE //--> 
   </div> 
   <div class="inner"> 
    <div class="content">
      Lorem 
    </div> 
    <div class="content">
      Lorem 
    </div> 
    <div class="content">
      Lorem 
    </div> 
    <div class="copyright">
      Lorem 
    </div> 
   </div> 
   <div class="inner"> 
    <div class="content">
      Lorem 
    </div> 
    <div class="content">
      Lorem 
    </div> 
    <div class="copyright">
      Lorem 
    </div> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials