Centering a child of an absolute position div tag - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

Centering a child of an absolute position div tag

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">
#banner {<!-- w  w w.j  a  v  a 2s. c  o m-->
   display:block;
   margin-left:auto;
   margin-right:auto;
}

img, #banner {
   width:100%;
}

#menu-outer {
   background:url('https://www.java2s.com/style/demo/Google-Chrome.png') repeat-x;
   z-index:100;
   position:absolute;
   top:26%;
   width:100%;
}

#menu {
   text-align:center;
}

#horizontal-list {
   display:inline-block;
}

ul#horizontal-list li {
   display:inline;
}

#menu a {
   text-decoration:none;
   margin:11px;
   float:left;
   color:Chartreuse;
   padding:3px 6px;
   text-align:center;
   white-space:nowrap;
}

#menu a:hover {
   color:yellow;
   background:red;
}
</style> 
 </head> 
 <body> 
  <div id="banner"> 
   <img src="https://www.java2s.com/style/demo/Google-Chrome.png"> 
  </div> 
  <div id="menu-outer"> 
   <div id="menu"> 
    <ul id="horizontal-list"> 
     <li> <a href="#">Lorem</a> </li> 
     <li> <a href="#">Lorem ip</a> </li> 
     <li> <a href="#">Lorem ipsu</a> </li> 
     <li> <a href="#">Lorem ipsum </a> </li> 
     <li> <a href="#">Lor</a> </li> 
     <li> <a href="#">Lorem i</a> </li> 
    </ul> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials