Center absolutely positioned div based on parent's width - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

Center absolutely positioned div based on parent's width

Demo Code

ResultView the demo in separate window

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head> 
  <title>Centering absolutely positioned div based on parent's</title> 
  <style type="text/css">
#menu-nav {<!--   ww w  . j  a v  a 2  s.  c  om-->
   list-style:none;
}

#menu-nav {
   float:right;
   clear:right;
   margin-top:31px;
   font-family:'Arvo'
}

#menu-nav li {
   list-style:none;
   margin:0 11px;
   float:left;
}

#menu-nav a {
   color:Chartreuse;
   padding:7px 10px;
   font-size:18px;
   background:yellow;
   text-decoration:none;
}

#menu-nav li.current-menu-item a {
   background:blue;
   color:pink;
}

#menu-nav li.current-menu-item {
   background:url('http://www.java2s.com/style/demo/Google-Chrome.png') no-repeat CENTER BOTTOM;
   padding-bottom:12px;
}
</style> 
 </head> 
 <body> 
  <ul id="menu-nav"> 
   <li> <a href="#">Home</a> </li> 
   <li> <a href="#">Artistse</a> </li> 
   <li> <a href="#">About</a> </li> 
   <li class="current-menu-item"> <a href="#">News</a> </li> 
   <li> <a href="#">Store</a> </li> 
   <li> <a href="#">Contact</a> </li> 
  </ul>  
 </body>
</html>

Related Tutorials