CSS Drop-down Navigation Bar Will Not Center - css

I realize this question has been asked over and over again, but I simply cannot figure out how to fix the problem. I'd like to center my drop-down navigation bar, the headers or main elements, not the child elements.
Here's the JSFiddle link :
http://jsfiddle.net/02zoptrf/3/
#mbwnavbar {
background: #ffffff;
width: 800px;
color: #000000;
margin: 0 auto;
padding: 0;
position: relative;
border-top:0px solid #transparent;
height:35px;
}
#mbwnav {
text-align: center
margin: 0 auto;
padding: 0;
}
#mbwnav ul {
float: left;
list-style: none;
margin: 0 auto;
padding: 0;
}
#mbwnav li {
list-style: none;
margin: 0 auto;
padding: 0;
display:inline;
border-left:0px solid #333;
border-right:0px solid #333;
height: 35px;
}
#mbwnav li a, #mbwnav li a:link, #mbwnav li a:visited {
color: #000000;
display: inline-block;
font:normal 11px Century Gothic, sans-serif; margin: 0;
font-weight: bold;
text-align: left;
padding: 9px 12px 10px 12px;
text-decoration: none;
}
#mbwnav li a:hover, #mbwnav li a:active {
background: #ffffff;
color: #fdeae9;
display: block;
text-decoration: none;
margin: 0 auto;
padding: 9px 12px 10px 12px;
}
#mbwnav li {
float: left;
padding: 0;
}
#mbwnav li ul {
z-index: 9999;
position: absolute;
left: -999em;
height: auto;
width: 100px;
margin: 0 auto;
padding: 0;
}
#mbwnav li ul a {
width: 100px;
}
#mbwnav li ul ul {
margin: -25px 0 0 161px;
}
#mbwnav li:hover ul ul, #mbwnav li:hover ul ul ul, #mbwnav li.sfhover ul ul, #mbwnav li.sfhover ul ul ul {
left: -999em;
}
#mbwnav li:hover ul, #mbwnav li li:hover ul, #mbwnav li li li:hover ul, #mbwnav li.sfhover ul, #mbwnav li li.sfhover ul, #mbwnav li li li.sfhover ul {
left: auto;
}
#mbwnav li:hover, #mbwnav li.sfhover {
position: static;
}
#mbwnav li li a, #mbwnav li li a:link, #mbwnav li li a:visited {
background: #ffffff;
width: 120px;
color: #000000;
display: block;
font:normal 11px Century Gothic, sans-serif;
margin: 0 auto;
padding: 9px 12px 10px 12px;
text-decoration: none;
z-index:9999;
border-bottom:0px dotted #333;
}
#mbwnav li li a:hover, #mbwnavli li a:active {
background: #ffffff;
color: #fdeae9;
display: block; margin: 0 auto;
padding: 9px 12px 10px 12px;
text-decoration: none;
}
Anyone have any ideas? Sorry for being such a bother, I realize this question is quite popular, but I've spent a few days working on this and I can't figure anything out.
Thank you!

An easy way to do this is with display: table on the container. Here's a demo, with some minor tweaks just to your CSS:
http://codepen.io/pageaffairs/pen/zvJmG

Try moving the text-align: center to #mbwnavbar and add display: inline-block to #mbwnav. text-align: center can center inline-blocks.
Example:
http://codepen.io/anon/pen/DGtfo

http://jsfiddle.net/VerdeletG/02zoptrf/7/
#mbwnav {
margin:auto;
display:table;
}
display table works extremely well with margin auto. I tweaked your code and removed unecessary lines as well while I was at it! hope it works!!!

I have been trying to fix this issue with the text not centering on Chrome mobile browsers and I have an answer and it worked after trying EVERYTHING!
"text-align:center;" does not work)
You dont need all that ridiculous code
Try this:
On a dropdown (select) CSS code the element with this
text-align-last: center;
All my dropdowns are now centered. I guess that code works because the browser is looking at the previous span but who knows it works!

Related

Align a navigation menu to the center

I need to get my navigation menu centered.
You can see my current menu at:
www.financialconsultingcareers.com
Here is the code:
#hor_nav
{
width: 100%;
color: #000000;
background: #f1f1f1;
font-size: 20px;
font-family: helvetica;
font-weight: bold;
height: 32px;
z-index: 1000;
Margin-top: -25px;
border-bottom: 5px solid #254117;
box-shadow: 0px 5px 5px #888888;
margin-bottom: 25px;
text-align: center;
}
#hor_nav UL
{
margin: 0;
}
#hor_nav LI
{
list-style: none;
display: center;
float: left;
margin-left: 3px;
padding: 0;
height: 32px;
position: relative;
text-transform: capitalize;
text-align: justify;
border-right: 1px solid #000001;
<!--left: 2.5%;-->
}
div.#hor_nav, ul.#hor_nav li.active a
{
border-radius: 5px 5px 0 0;
margin-right: 3px;
}
#hor_nav LI A
{
display: inline-block;
padding: 0 18px;
line-height: 32px;
margin-right: 3px;
color: #000;
font-weight: normal;
font-size: 100%;
text-decoration: none;
border-radius: 5px 5px 0 0;
text-align: justify;
}
#hor_nav LI.active A
{
border-radius: 4px 4px 0 0;
background-color: #254117;
color: #FFFFFF;
font-weight: normal;
padding-bottom: 4px;
margin-top: -4px;
}
#hor_nav li:last-child
{
border-right: none;
}
#hor_nav LI A:hover,
#hor_nav LI:hover A,
#hor_nav LI.sfHover A
{
background: #828282;
color: #FFF;
text-decoration: none;
border-radius: 5px 5px 0 0;
padding-bottom: 4px;
margin-top: -4px;
}
#hor_nav LI UL
{
position: absolute;
width: auto;
left: -999em;
margin-left: -4px;
border-radius: 5px 5px 0 0;
}
#hor_nav LI UL UL
{
margin: -31px 0 0 170px;
border-radius: 5px 5px 0px 0px;
}
#hor_nav LI:hover UL UL,
#hor_nav LI:hover UL UL UL,
#hor_nav LI:hover UL UL UL UL,
#hor_nav LI.sfHover UL UL,
#hor_nav LI.sfHover UL UL UL,
#hor_nav LI.sfHover UL UL UL UL
{
left: -999em;
}
#hor_nav LI LI
{
margin-left: -20px;
padding: 0;
font-size: 80%;
height: auto;
text-align: justify;
background: #CCC;
width: 225px;
border-radius: 0 0 0 0;
box-shadow: 0px 3px 3px #888888;
}
#hor_navLI LI A,
#hor_nav LI LI.active A,
#hor_nav LI LI A:hover
{
margin: 0;
height: 30px;
line-height: 30px;
background: #828282;
color: #FFF;
border-radius: 5px 5px 5px 5px;
}
#hor_nav LI LI A,
#hor_nav LI.active LI A
{
font-weight: normal;
border-radius: 5px 5px 0 0;
}
#hor_nav LI:hover UL,
#hor_nav LI.sfHover UL
{
left: 4px;
}
#hor_nav LI LI:hover UL,
#hor_nav LI LI LI:hover UL,
#hor_nav LI LI LI LI:hover UL,
#hor_nav LI LI.sfHover UL,
#hor_nav LI LI LI.sfHover UL,
#hor_nav LI LI LI LI.sfHover UL
{
left: 0;
}
#hor_nav LI
{
list-style: none;
}
It does not solve everything, but if you add a fixed width (say, width: 700px) to the <ul class="hor_nav">, the menu is centered (however, the background does not persist through the full width of the page, but you have to set the background to a different element in order to support that).
You must specify a fixed width in order for margin-left: auto and margin-right: auto to center the element.
There is no such thing as position: center. You can drop that one.
By the way, I notice the top logo is shrunk when you resize the page. Beware. ;)
If you want to center your navigation menu, you need to set a fixed width value to your UL. This is going to change how you implement your design though. So you may need to use the parent div in order to apply your border and background colors.
You have to specify a certain width. 100% would not work...
Example:
#hor_nav {
width: 500px;
margin: 0 auto;
The margin: 0 auto will centre it dead on but it will only work if you have a certain width applied to your element.

Alignment of submenu

I am unable to get rid of a gap between my nav bar and my submenu dropdown menu. You can view the issue here.
My css is here:
nav#nav{
float: left;
font: 14px/16px 'MuseoSlab500Regular', arial, helvetica, sans-serif;
margin-right: auto;
z-index: 99999;
/*background-image: url(../images/2blkbg.png);*/
/*background-repeat: repeat-x;*/
padding-left: 30px;
/*background-position: left bottom;*/
background-color: #000;
height: 53px;
display: block;
position: relative;
margin-top: 15px;
margin-bottom: 15px;
}
#nav ul{
list-style: none;
margin: 0;
padding: 0;
}
#nav ul li{
float: left;
margin-right: 0;
margin-bottom: 0;
padding-top: 0;
padding-right: 49px;
padding-bottom: 0;
padding-left: 0;
}
#nav ul a,#nav li.current-menu-ancestor a{
display: block;
height:83px;
line-height: 53px;
border-top-width: 0px;
border-top-style: solid;
border-top-color: #fff;
}
#nav ul .current_page_item a, #nav ul .current-menu-item a, #nav ul > .current-menu-parent a{
color:#a0ce4e;
text-decoration:none;
border-color:#a0ce4e;
}
#nav ul li{
position: relative;
}
#nav ul ul{
display: none;
position: absolute;
top: 0px;
left: 0;
width: 170px;
background: #edebeb;
z-index: 100000;
border-top: 3px solid #a0ce4e;
z-index: 99999;
}
#nav ul li:hover ul{
display: block;
}
#nav ul li ul li{
display: block;
float: none;
margin: 0;
padding: 0;
background-image: url(../images/blkbg.png);
background-repeat: repeat-x;
}
#wrapper #nav ul li ul li a{
background: url(../images/subnav_sep.jpg) repeat-x bottom left;
border: 0;
height: 30px;
text-indent: 20px;
font: 13px/30px 'PTSansRegular', Arial, Helvetica, sans-serif;
color: #333333 !important;
}
#wrapper #nav ul li ul li a:hover,#wrapper #nav ul li ul li.current-menu-item a{
background-color:rgba(255,255,255,0.5);
}
#nav ul ul ul{
display:none !important;
}
#nav ul ul li:hover ul{
display:block !important;
top:-3px;left:170px;
}
#nav select{
max-width:100%;
display:none;
}
#nav > li > a,#nav li.current-menu-ancestor a {
height:83px;
line-height:83px;
}
#nav ul ul {
top:86px;
}
Set the top and that will remove the excess of gap:
#nav ul ul {
top:86px;
}
Good you posted the url, since problem is not in the css you included. The problem is in this class:
#nav ul ul {
top:86px;
}
This top-offset should be set to 53px, the same height as your menu bar (nav#nav):
#nav ul ul {
top:53px;
}
This css-class actually is not in your css-stylesheet, but in your page itself. It is included in the <head></head>.

Want nav menu over background image on splash page but it moves around on various monitors

I'm pretty sure this is an easy fix and I am simply too in experienced to figure it out. I'm building a site, using WP, but the home page is simply a background image with a vertical nav menu. I don't now how to make the menu stay in the same place for all browsers and windows. It looked good on my screen, then I found the nav pane was in a completely different place on my husband's monitor. I believe it has to do with position and display and margins, but I am getting more lost as I read up on these and I just want someone to tell me the code.
The page is at www.sydneyjanebaily.com
So far the code for the whole page is as follows:
body {
background-image:url(http://www.sydneyjanebaily.com/wp-content/themes/twentyeleven/images/open-book.png);
background-repeat:no-repeat; background-attachment:fixed;
background-position:center;
}
menu { display: block; }
access div { display: block; margin-left:890px; margin-right:auto; margin-top:200px; width: 235px; }
/************* Navigation **********/
nav#access ul, nav#access li.pagenav { display: block; list-style:
none; }
nav#access ul li a span, nav#access ul li.page_item a span { position:
absolute; right: 100%; top: 2px; width: 15px; height: 100%;
background-image: url(../images/nav-shadow.png); background-position:
right top; background-repeat: repeat-y; }
nav#access ul li a, nav#access ul li a:visited, nav#access ul
li.page_item a, nav#access ul li.page_item a:visited { display:
block; padding: 8px 10px 8px 30px; color: white; font: 150%
"EBGaramondSC", "Palatino", "Palatino Linotype","Book Antiqua",
Georgia, serif; text-decoration: none; /*background-color:
aba000; */ margin: 5px 0 7px 0; position: relative; width: 235px; /font-variant: small-caps;/ }
nav#access ul li a:hover, nav#access ul li a:focus, nav#access ul
li.page_item a:hover, nav#access ul li.page_item a:focus{ color:
FF0000; }
nav#access li a:hover span { background-color: #666; } nav#access ul
li a em { font-size: 87.50%; } nav#access ul li:nth-child(5n-4) a,
nav#access ul li:nth-child(5n-4) a span { ; } nav#access ul
li:nth-child(5n-3) a, nav#access ul li:nth-child(5n-3) a span { ; }
nav#access ul li:nth-child(5n-2) a, nav#access ul li:nth-child(5n-2) a
span { ; } nav#access ul li:nth-child(5n-1) a, nav#access ul
li:nth-child(5n-1) a span { ; } nav#access ul li:nth-child(5n-5) a,
nav#access ul li:nth-child(5n-5) a span {; } -->
nav#access ul li ul li span { position: absolute; right: 100%; top: 0;
width: 20px; height: 100%; left: 2px; margin-right: 15px; overflow:
visible; } nav#access ul li ul li:nth-child(odd) a { background:
none; color: #EEE8AA; font-size: smaller; margin: 3px 20px 5px 20px;
min-height: 20px; width: 210px; padding: 2px 0 2px 20px; } nav#access
ul li ul li:nth-child(odd) a:hover, nav#access ul li ul
li:nth-child(odd) a:focus { background: none; color: #ADFF2F;
font-size: smaller; left: 15px; padding: 2px 30px 2px 25px; }
nav#access ul li ul li:nth-child(odd) a span { background:
url(../images/sub-menu2.png) -5px 0px no-repeat; width: 30px; }
nav#access ul li ul li:nth-child(even) a { background: none; color:
3B3C1D; font-size: smaller; margin: 3px 20px 5px 20px; min-height: 20px; width: 210px; padding: 2px 0 2px 20px; } nav#access ul li ul
li:nth-child(even) a:hover, nav#access ul li ul li:nth-child(even)
a:focus { background: none; color: #FF4500; font-size: smaller; left:
15px; padding: 2px 30px 2px 25px; } nav#access ul li ul
li:nth-child(even) a span { background: url(../images/sub-menu2.png)
-5px 0px no-repeat; width: 30px; }
nav#access ul li ul li ul li:nth-child(odd) a { background: none;
color: #FFD700; font-size: smaller; margin: 3px 20px 5px 30px;
min-height: 20px; width: 200px; padding: 2px 0 2px 20px; } nav#access
ul li ul li ul li:nth-child(odd) a:hover, nav#access ul li ul li ul
li:nth-child(odd) a:focus { background: none; color: #EEE8AA;
font-size: smaller; left: 25px; padding: 2px 30px 2px 25px; }
nav#access ul li ul li ul li:nth-child(odd) a span { background:
url(../images/sub-menu.png) -10px 0px no-repeat; width: 30px; }
nav#access ul li ul li ul li:nth-child(even) a { background: none;
color: #3B3C1D; font-size: smaller; margin: 3px 20px 5px 30px;
min-height: 20px; width: 200px; padding: 2px 0 2px 20px; } nav#access
ul li ul li ul li:nth-child(even) a:hover, nav#access ul li ul li ul
li:nth-child(even) a:focus { background: none; color: #7FFFD4;
font-size: smaller; left: 25px; padding: 2px 30px 2px 25px; }
nav#access ul li ul li ul li:nth-child(even) a span { background:
url(../images/sub-menu.png) -10px 0px no-repeat; width: 30px; }
nav#access ul li a:hover:active, nav#access ul li ul li
a:hover:active, nav#access ul li ul li ul li a:hover:active,
nav#access ul li a:focus:active, nav#access ul li ul li
a:focus:active, nav#access ul li ul li ul li a:focus:active { color:
00CCFF; left: 1px; top: 1px;}
/* Singular navigation */
nav-single { float: right; position: relative; top: -0.3em; text-align: right; z-index: 1; }
nav-single .nav-previous,
nav-single .nav-next { float: none; width: auto; }
nav-single .nav-next { padding-left: .5em; }
img.book {
/* Set rules to fill background */
min-height: 100%;
min-width: 1000px;
/* Set up proportionate scaling */
height: auto;
/* Set up positioning */
top: 0;
left: 0;
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
<!-- <img class="book"src="<?php bloginfo('template_directory');?>/images/open-book.png" alt="xxx"
width="880" height="xxx" /> -->
<?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
<!-- <div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content',
'twentyeleven' ); ?>">
"> -->
'primary' ) ); ?>
I am puzzled that when I inspect an element using Firefox developer tool, it still says inline element for things I've marked as block.
Basically, I can put the nav pane where I want using px but it only looks right on my screen. I think I need percentages, but that is beyond me. Please help.
Thanks,
Sydney
Try replacing this:
#access div {
display: block;
margin-left:890px;
margin-right:auto;
margin-top:200px;
width: 235px;
}
with this:
#access div {
position: absolute;
top: 20%;
left: 50%;
}
It works well on my monitor no matter how I squash or stretch the screen, and it should work for you as well. Good luck!

Wordpress Menu UL height

I have some pretty good experince coding my own UL's but I'm relatively new to wordpress. Confusing to me to work backwards especially when I can't see the html. Anyway I'm using the cufon WP plugin to change the font in the menu. but....with the size I want the font, it shrinks the list item as well as the a:hover. There is somehting in the padding i presume, but I can't find it. you can see what I mean here http://www.thedailyminx.com
here is the menu's css
#navbar {
float: left;
display: block;
background: #bfbcc6;
color: #000000;
width: 978px;
height: 30px;
font-size: 25px;
font-family: 'jc-hand';
margin: 15px auto 15px;
padding: 0px 0px 0px 0px;
border: 1px solid #DDDDDD;
position: relative;
z-index: 9;
}
/*** ESSENTIAL STYLES ***/
.menu, .menu * {
margin: 0;
padding: 0;
list-style: none;
}
.menu {
line-height: 1.0;
}
.menu ul {
margin: 0px;
padding: 0px;
}
.menu ul ul, ul.menu ul {
position: absolute;
top: -9999px;
width: 160px; /* left offset of submenus need to match (see below) */
}
.menu ul li ul li, ul.menu ul li {
width: 100%;
margin: 0px 0px 0px 0px;
}
.menu li:hover {
visibility: inherit; /* fixes IE7 'sticky bug' */
}
.menu li {
float: left;
display: inline-block;
position: relative;
}
.menu a {
display: inline-block;
position: relative;
}
.menu li:hover ul,
.menu li.sfHover ul {
left: 0;
top: 30px; /* match top ul list item height */
z-index: 99;
}
ul.menu li:hover li ul,
ul.menu li.sfHover li ul {
top: -9999px;
}
ul.menu li li:hover ul,
ul.menu li li.sfHover ul {
left: 160px; /* match ul width */
top: 0;
}
ul.menu li li:hover li ul,
ul.menu li li.sfHover li ul {
top: -9999px;
}
ul.menu li li li:hover ul,
ul.menu li li li.sfHover ul {
left: 160px; /* match ul width */
top: 0;
}
/*** SKIN ***/
.menu .current_page_item a,
.menu .current_page_ancestor a,
.menu .current-menu-item a,
.menu .current-cat a {
background: #333333;
color: #FFFFFF;
border-left: 1px solid #333333;
border-right: 1px solid #333333;
}
.menu li .current_page_item a, .menu li .current_page_item a:hover,
.menu li .current-menu-item a, .menu li .current-menu-item a:hover,
.menu li .current-cat a, .menu li .current-cat a:hover {
background: #333333 !important;
color: #FFFFFF !important;
border-left: none;
border-right: none;
}
.menu {
float: left;
margin-bottom: 0;
}
.menu a {
color: #000000;
background: none;
margin: 0px 0px 0px 0px;
padding: 0px 12px 0px 12px;
text-decoration: none;
letter-spacing: 0.1px;
line-height: 30px;
border-right: 1px solid #DDDDDD;
border-left: 1px solid #FFFFFF;
}
.menu li li a {
display: block;
background: #F5F5F5 !important;
color: #000000 !important;
margin: 0px 0px 0px 0px;
padding: 0px 10px 0px 10px;
font-size: 25px;
line-height: 30px;
text-decoration: none;
text-transform: none;
text-shadow: none;
letter-spacing: 0px;
border-right: none !important;
border-left: none !important;
}
.menu li, .menu li li, .menu li li li {
background: none;
margin: 0px;
padding: 0px;
}
.menu li:hover, .menu li.sfHover {
margin: 0px;
padding: 0px;
}
.menu a:focus, .menu a:hover, .menu a:active {
background: #333333;
color: #FFFFFF;
border-right: 1px solid #333333;
border-left: 1px solid #333333;
outline: 0;
}
.menu li li:hover, .menu li li.sfHover {
margin: 0px;
padding: 0px;
}
.menu li li a:focus, .menu li li a:hover, .menu li li a:active {
background: #EEEEEE !important;
color: #333333 !important;
border: none;
outline: 0;
}
can anyone help me out?
Thanks
Greg
ditch the inline height styling of cufon and set it in your stylesheet to 30px

CSS drop down menu is working in Mozilla, Chrome but not in IE

I implemented a drop down navigation menus in my blog, but it's not working properly in IE (any version). It's working in Chrome and Mozilla fine.
What should be done to make it compatible to IE?
The CSS I added is below:
#mbtnavbar {
/* background: #B0E2FF;*/
width: 780 px;
color: #FFF;
margin: 0 px;
padding: 0;
position: relative;
border-top:5 px solid #960100;
height:30 px;
}
#mbtnav {
margin: 0;
padding: 0;
}
#mbtnav ul {
float: left;
list-style: none;
margin: 0;
padding: 0;
}
#mbtnav li {
list-style: none;
margin: 0;
padding: 0;
border-left:0 px solid #333;
border-right:0 px solid #333;
height:35px;
}
#mbtnav li a, #mbtnav li a:link, #mbtnav li a:visited {
color: ;
display: block;
font:normal 13px Trebuchet MS, sans-serif;
margin: 5;
padding: 9px 12px 10px 12px;
text-decoration: none;
}
#mbtnav li a:hover, #mbtnav li a:active {
background: #0066FF;
color: #FFF;
display: block;
text-decoration: none;
margin: 0;
padding: 9px 12px 10px 12px;
}
#mbtnav li {
float: left;
padding: 0;
}
#mbtnav li ul {
z-index: 9999;
position: absolute;
left: -999em;
height: auto;
/*Width of drop down menu*/
width: 180px;
margin: -2px;
padding: 0;
}
#mbtnav li ul a {
width: 140px;
}
#mbtnav li ul ul {
margin: -25px 0 0 161px;
}
#mbtnav li:hover ul ul, #mbtnav li:hover ul ul ul, #mbtnav li.sfhover ul ul, #mbtnav li.sfhover ul ul ul {
left: -999em;
}
#mbtnav li:hover ul, #mbtnav li li:hover ul, #mbtnav li li li:hover ul, #mbtnav li.sfhover ul, #mbtnav li li.sfhover ul, #mbtnav li li li.sfhover ul {
left: auto;
}
#mbtnav li:hover, #mbtnav li.sfhover {
position: static;
}
#mbtnav li li a, #mbtnav li li a:link, #mbtnav li li a:visited {
background: #B0E2FF;
width: 360px;
color: ;
display: block;
font:normal 13px Trebuchet MS, sans-serif;
margin: 0;
padding: 9px 12px 10px 12px;
text-decoration: none;
z-index:9999;
border-bottom:1px dotted #333;
}
#mbtnav li li a:hover, #mbtnavli li a:active {
background: #0066FF;
color: #FFF;
display: block;
margin: 0;
padding: 9px 12px 10px 12px;
text-decoration: none;
}
Thanks in advance
Anand
First, fix your errors. The site has 307 validation errors. invalid markup is the #1 reason why pages don't render properly from one browser to another. Many people (myself included) won't even look at your CSS until you have valid markup.

Resources