Horizontally center a menu - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Menu

Description

Horizontally center a menu

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">
body {<!--  w  w  w .j av  a  2  s  . c  o  m-->
   background:red;
}

.menu-container {
   position:absolute;
   top:21px;
   margin-right:auto;
   margin-left:auto;
   width:100%;
}

nav {
   float:right;
   width:100%;
   text-align:center;
}

nav ul {
   margin-right:-5px;
   margin-left:6px;
}

nav ul li {
   display:inline-block;
   margin-right:-5px;
   margin-left:6px;
}

nav a {
   padding:8px 11px;
   text-decoration:none;
   color:Chartreuse;
   background:yellow;
   border-radius:6px;
   font-weight:301;
   text-transform:uppercase;
   letter-spacing:2.6px;
   font-size:15px;
   font-weight:401;
}

nav a:hover {
   background:blue
}

.activeNav {
   background:pink
}

nav ul li ul {
   position:absolute;
   display:block;
   margin-top:6px;
   border-radius:6px;
   border-top-left-radius:0;
   background:none;
   padding-top:6px
}

nav ul li ul li {
   display:block;
   float:none;
   margin:0;
   padding:0
}

nav ul li ul li a {
   display:block;
   text-align:left;
   color:OrangeRed;
   text-shadow:0 2px grey;
   padding:11px
}

nav ul li ul li a:hover {
   background:BlueViolet;
   color:Chartreuse;
   text-shadow:0 2px yellow
}

.hover a {
   display:block;
}

.hover span {
   color:blue;
   background:pink;
   border-radius:6px;
   position:absolute;
   display:block;
   margin:6px 0 0 -58px;
   padding:11px;
   font-size:14px;
   font-weight:301;
   letter-spacing:2.6px;
   text-transform:uppercase;
   text-align:center;
   cursor:default;
}
</style> 
 </head> 
 <body> 
  <header class="clearfix"> 
   <div class="menu-container"> 
    <nav> 
     <ul> 
      <li> <a href="biographie.html">Lorem ipsu</a> </li> 
      <li> <a href="espace-coaching.html">Lorem ipsum dol</a> 
       <ul> 
        <li> <a href="#">Lorem </a> </li> 
        <li> <a href="#">Lorem ips</a> </li> 
       </ul> </li> 
      <li> <a href="espace-nutrition.html">Lorem ipsum dolo</a> 
       <ul> 
        <li> <a href="#">Lorem ipsum</a> </li> 
        <li> <a href="#">Lorem ips</a> </li> 
       </ul> </li> 
      <li> <a href="#">Lorem i</a> </li> 
     </ul> 
    </nav> 
   </div> 
   <div class="down-arrow"> 
    <i class="fa fa-angle-down"></i> 
   </div> 
   <div id="news_box" style="position: absolute; bottom:20px; right: 20px; max-width: 380px; float: right; text-align: left;"></div> 
  </header>  
 </body>
</html>

Related Tutorials