Using :before and :after to add border to a div - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Border

Description

Using :before and :after to add border to a div

Demo Code

ResultView the demo in separate window

<html lang="en">
 <head> 
  <style>
.innerCnt {<!--from   ww  w .j  ava  2 s . c o m-->
   background:Chartreuse;
   position:relative;
   z-index:2;
   border-radius:6px;
}

.innerCnt ul {
   margin:0
}

.borderBox {
   height:100px;
   border:2px solid yellow;
   border-radius:9px;
   position:relative;
}

.borderBox:after,
.borderBox:before {
   border:2px solid blue;
   content:" ";
   position:absolute;
   height:100%;
   width:100%;
   top:2px;
   border-radius:9px;
}

.borderBox:after {
   top:4px;
   border-radius:8px;
}
</style> 
 </head> 
 <body translate="no"> 
  <div class="borderBox"> 
   <div class="innerCnt"> 
    <ul> 
     <li>Lorem Ipsum</li> 
     <li>Lorem Ipsum</li> 
     <li>Lorem Ipsum</li> 
     <li>Lorem Ipsum</li> 
    </ul> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials