Vertical aligning a child element with position absolute and margin auto - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

Vertical aligning a child element with position absolute and margin auto

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">
.parent {<!--from   w  w  w.  ja v  a  2 s  . co m-->
   position:relative;
   margin:51px;
   border:2px solid Chartreuse;
}

.child {
   position:absolute;
   margin:auto;
   height:61px;
   width:41px;
   top:51%;
   transform:translateY(-51%);
   right:0;
   background:blue;
   opacity:0.4;
}
</style> 
 </head> 
 <body> 
  <div class="parent"> 
   <div>
     Lorem ip 
   </div> 
   <div class="child"></div> 
  </div>  
 </body>
</html>

Related Tutorials