center a div inside an absolutely positioned div - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

center a div inside an absolutely positioned div

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">
.outer {<!--from   w w  w  . jav a 2  s . c o  m-->
   position:absolute;
   left:0;
   right:0;
   top:51px;
   height:auto;
   background:Chartreuse;
   border:2px solid yellow;
}

.inner {
   display:block;
   margin:11px;
   border:2px solid blue;
   text-align:center;
}

.center {
   margin:11px 0;
   text-align:left;
   height:41px;
   width:81%;
   display:inline-block;
   background:pink;
   padding:11px;
}
</style> 
 </head> 
 <body> 
  <div class="outer"> 
   <div class="inner"> 
    <div class="center">
      Lorem ipsum d 
    </div> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials