horizontally center an absolute positioned element inside a 100% width div - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

horizontally center an absolute positioned element inside a 100% width 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">
#header {<!--  w  w  w  .  j  av a  2  s  . c  o  m-->
   background:black;
   height:51px;
   width:100%;
}

#logo {
   background:red;
   height:51px;
   position:absolute;
   width:51px;
   margin:0 auto;
   right:0;
   left:0;
}
</style> 
 </head> 
 <body> 
  <div id="header"> 
   <div id="logo"></div> 
  </div>  
 </body>
</html>

Related Tutorials