html - Issue to horizontally center a menu -
i'm trying center (horizontally) horizontal menu middle of page without success. i've put menu in container has margins left , right set auto, doesn't work. http://jsfiddle.net/nb6x4/
/***** menu *******/ .menu-container { position: absolute; top: 20px; margin-right: auto; margin-left: auto; width: 100%; } nav { float: right; margin: 20px auto; width: 100%; } nav ul { margin-right: -4px; margin-left: 5px; } nav ul li { display: inline-block; margin-right: -4px; margin-left: 5px; vertical align: top; } nav { padding: 7px 10px; text-decoration: none; color: rgba(255,255,255,0.9); background: rgba(0,0,0,0); border-radius: 5px; font-weight: 300; text-transform: uppercase; letter-spacing: 1.5px; font-size: 14px; font-weight: 400; } nav a:hover { background: rgba(0,0,0,0.25) } .activenav { background: rgba(0,0,0,0.25) } nav ul li ul { position: absolute; display: block; margin-top: 5px; border-radius: 5px; border-top-left-radius: 0; background: none; padding-top: 5px } nav ul li ul li { display: block; float: none; margin: 0; padding: 0 } nav ul li ul li { display: block; text-align: left; color: rgba(255,255,255,0.9); text-shadow: 0 1px rgba(0,0,0,0.33); padding: 10px } nav ul li ul li a:hover { background: rgba(20,150,220,0.5); color: white; text-shadow: 0 1px rgba(0,0,0,0.5) } .hover { display: block; } .hover span { color: rgba(255,255,255,0.9); background: rgba(20,150,220,0.5); border-radius: 5px; position: absolute; display: block; margin: 5px 0 0 -57px; padding: 10px; font-size: 13px; font-weight: 300; letter-spacing: 1.5px; text-transform: uppercase; text-align: center; cursor: default; } /**** end menu ****/
there few things need re-evaluate.
first of all, absolutely positioned container can not centered margin, margin: 0 auto; effects relatively positioned elements.
so first thing need delete position: absolute; on .menu_container.
.menu-container { top: 20px; margin-right: auto; margin-left: auto; width: 100%; } then, div relatively positioned, have property width set 100%. makes div take full amount of width available whatever element it's parent. adding margin: 0 auto; doesn't , left , right sides of element touching sides of parent. can't center "fits perfectly" speak in it's parent.
so there few things can do. can shrink size of container, 80%, , start center container element, not centering nav links.
the better option in opinion use text-align: center; center li's since using display: inline-block. retain block characteristics treated "normal text" speak.
simply changing selector have below should need...
nav ul { text-align: center; margin-right: -4px; margin-left: 5px; }
Comments
Post a Comment