center absolutely positioned element in div - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

center absolutely positioned element in div

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <style>
.parent<!--from  ww w . j  a v  a2  s. c  om-->
 {
   position:relative;
}

.child
 {
   position:absolute;
   top:0 ;
   right:0 ;
   bottom:0 ;
   left:0 ;
   margin:auto;
}

.parent
 {
   width:301px;
   height:301px;
   background:red;
}

.child
 {
   width:100px;
   height:100px;
   background:blue;
   text-align:center;
   line-height:100px;
}
</style> 
 </head> 
 <body> 
  <div class="parent"> 
   <div class="child"> 
    <!-- content --> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials