Position item in a center - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Position

Description

Position item in a center

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">
.main {<!-- w  w w.  j  a va 2  s.  c  o m-->
   height:201px;
   width:201px;
   background:Chartreuse;
   position:relative;
}

.caption {
   position:absolute;
   height:auto;
   text-align:center;
   zoom:2;
   color:yellow;
   display:table;
   left:21%;
   top:51%;
   transform:translate(0,-51%);
   width:61%;
   margin-top:auto;
   margin-bottom:auto;
   padding:11px 0;
   background:blue;
}
</style> 
 </head> 
 <body> 
  <div class="main"> 
   <div class="caption">
     Lorem ip 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials