Apply margin-right to divs with a sibling to their right - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Div

Description

Apply margin-right to divs with a sibling to their right

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">
.halfPanel {<!--   w w w .  j a  va  2 s. c  om-->
   width:49%;
   display:inline-block;
   height:49%;
   border:2px solid Chartreuse;
   text-align:center;
   margin-bottom:5%;
}

.fullPanel {
   width:100%;
   display:inline-block;
   height:100%;
   border:2px solid yellow;
   text-align:center;
   margin-bottom:5%;
}

div.halfPanel:first-child {
   border-color:blue;
}

div.halfPanel~div.halfPanel {
   border-color:pink;
}
</style> 
 </head> 
 <body> 
  <div class="halfPanel">
    TEST 
  </div> 
  <div class="halfPanel">
    TEST 
  </div> 
  <div class="halfPanel">
    TEST 
  </div> 
  <div class="halfPanel">
    TEST 
  </div> 
  <div class="halfPanel">
    TEST 
  </div> 
  <div class="fullPanel">
    TEST 
  </div> 
  <div class="fullPanel">
    TEST 
  </div>  
 </body>
</html>

Related Tutorials