Vertically align a div within a position:absolute parent - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

Vertically align a div within a position:absolute parent

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">
.out {<!--   w w  w .j av  a  2  s.c o m-->
   width:100%;
   height:501px;
   background-color:Chartreuse;
   position:relative;
}

.container {
   position:absolute;
   height:100%;
   width:51%;
   right:0;
   top:0;
   background-color:yellow;
}

.content {
   background-color:blue;
   position:absolute;
   width:100%;
   height:41px;
   top:calc(51% - 21px);
}
</style> 
 </head> 
 <body> 
  <div class="out"> 
   <div class="container"> 
    <div class="content"> 
     <p>Lorem</p> 
    </div> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials