Count indicator adds extra spaces in a CSS menu - css

I need to add Faceboook style count indicators to a CSS menu. You can see it here: JSFIDDLE
The problem is that count indicators (with orange background) creates extra spaces and I can't understand why.
First problem:
As you can see in the above image, the texts "Two" and "Four" (with number indicators) are placeed 1px lower than texts "One" and "Three" (without number indicators).
Second problem:
As you can see the width of left and right margins of the text "Two" (with number indicator) are different. The with of left margin is 10px as it should be but the width of right margin is 15px.
My code:
html{height:100%;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote{padding:0;margin:0;}
body{cursor:default;font:11px/13px verdana,tahoma,arial;color:#333;background-color:#ffffff;}
div#xx2menus{margin:0px auto;width:968px;height:36px;background:#5B4B40;background: -webkit-linear-gradient(#776753, #5B4B40);background: -o-linear-gradient(#776753, #5B4B40);background: -moz-linear-gradient(#776753, #5B4B40);background: linear-gradient(#776753, #5B4B40);border:1px solid #362D26;border-radius:3px;z-index:999}
#xx2menu,#xx2menu ul{list-style:none;}
#xx2menu{float:left;font-family:Arial;}
#xx2menu > li{float: left;}
#xx2menu li a{display:block;padding:11px 10px 12px 10px;text-decoration:none;}
#xx2menu ul {position:absolute;display:none;z-index:999;}
#xx2menu ul li a{width:80px;}
#xx2menu li:hover ul{display: block;}
#xx2menu > li > a{color: #fff;font-weight:700;}
#xx2menu > li:hover > a{background: #EAD593;color: #000;}
#xx2menu ul{border-bottom-right-radius:3px;border-bottom-left-radius:3px}
#xx2menu ul li a{color:#000;}
#xx2menu ul li:hover a{background: #ffc97c;}
span.badge{
display:inline-block;
padding: 1px 5px 1px 5px;
text-align:center;
color:#fff !important;
font-size:10px;
line-height:13px;
/*-webkit-border-radius:3px;*/
-moz-border-radius:3px;
border-radius:3px;
-o-border-radius:3px;
-khtml-border-radius:3px;
}
a span.badge{
position:relative;
top:-16px;
right:5px;
margin:0;
}
span.badge.on{
background-color:#f60;
color: #ffffff !important;
}
.lsub:nth-child(odd){background-color:#EFDEAB}
.lsub:nth-child(even){background-color:#EAD593;}
HTML
<div id="xx2menus">
<ul id="xx2menu">
<li>One</li>
<li>Two<span class="badge on">5</span></li>
<li>Three</li>
<li>Four<span class="badge on">17</span>
<ul>
<li class="lsub">Submenu1</li>
<li class="lsub">Submenu2</li>
</ul>
</li>
</ul>
</div>

here is your answer, what you have to do is
a span.badge{position:absolute;} but at the same time you have to change the
li a{position:relative} to control the position of the badges check the code below.
html{height:100%;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote{padding:0;margin:0;}
body{cursor:default;font:11px/13px verdana,tahoma,arial;color:#333;background-color:#ffffff;}
div#xx2menus{margin:10px auto 0px;width:968px;height:36px;background:#5B4B40;background: -webkit-linear-gradient(#776753, #5B4B40);background: -o-linear-gradient(#776753, #5B4B40);background: -moz-linear-gradient(#776753, #5B4B40);background: linear-gradient(#776753, #5B4B40);border:1px solid #362D26;border-radius:3px;z-index:999}
#xx2menu,#xx2menu ul{list-style:none;}
#xx2menu{float:left;font-family:Arial;}
#xx2menu > li{float: left;}
#xx2menu li a{display:block;padding:11px 10px 12px 10px;text-decoration:none;}
#xx2menu ul {position:absolute;display:none;z-index:999;}
#xx2menu ul li a{width:80px;}
#xx2menu li:hover ul{display: block;}
#xx2menu > li > a{color: #fff;font-weight:700;}
#xx2menu > li:hover > a{background: #EAD593;color: #000;}
#xx2menu ul{border-bottom-right-radius:3px;border-bottom-left-radius:3px}
#xx2menu ul li a{color:#000; position:relative; display:inline-block;}
#xx2menu ul li:hover a{background: #ffc97c;}
span.badge{
display:inline-block;
padding: 1px 5px 1px 5px;
text-align:center;
color:#fff !important;
font-size:10px;
line-height:13px;
/*-webkit-border-radius:3px;*/
-moz-border-radius:3px;
border-radius:3px;
-o-border-radius:3px;
-khtml-border-radius:3px;
}
li a{ position:relative; display:inline-block;}
a span.badge{
position:absolute;
top:-5px;
right:0px;
margin:0;
}
span.badge.on{
background-color:#f60;
color: #ffffff !important;
}
.lsub:nth-child(odd){background-color:#EFDEAB}
.lsub:nth-child(even){background-color:#EAD593;}
<div id="xx2menus">
<ul id="xx2menu">
<li>One</li>
<li>Two<span class="badge on">5</span></li>
<li>Three</li>
<li>Four<span class="badge on">17</span>
<ul>
<li class="lsub">Submenu1</li>
<li class="lsub">Submenu2</li>
</ul>
</li>
</ul>
</div>

You need to give the badges an absolute position, inside a relative parent, and set some proper margins to them.
#xx2menu > li > a{
color: #fff;font-weight:700;position: relative;
}
a span.badge{
position:absolute;
top:0;
right:5px;
margin:-7px -7px 0 0;
}
http://jsfiddle.net/ufj27m4w/12/

Add position: relative to #xx2menu > li or #xx2menu > li > a and position: absolute to a span.badge
html{height:100%;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote{padding:0;margin:0;}
body{cursor:default;font:11px/13px verdana,tahoma,arial;color:#333;background-color:#ffffff;}
div#xx2menus{margin:0px auto;width:968px;height:36px;background:#5B4B40;background: -webkit-linear-gradient(#776753, #5B4B40);background: -o-linear-gradient(#776753, #5B4B40);background: -moz-linear-gradient(#776753, #5B4B40);background: linear-gradient(#776753, #5B4B40);border:1px solid #362D26;border-radius:3px;z-index:999}
#xx2menu,#xx2menu ul{list-style:none;}
#xx2menu{float:left;font-family:Arial;}
#xx2menu > li{float: left;position: relative;}
#xx2menu li a{display:block;padding:11px 10px 12px 10px;text-decoration:none;}
#xx2menu ul {position:absolute;display:none;z-index:999;}
#xx2menu ul li a{width:80px;}
#xx2menu li:hover ul{display: block;}
#xx2menu > li > a{color: #fff;font-weight:700;}
#xx2menu > li:hover > a{background: #EAD593;color: #000;}
#xx2menu ul{border-bottom-right-radius:3px;border-bottom-left-radius:3px}
#xx2menu ul li a{color:#000;}
#xx2menu ul li:hover a{background: #ffc97c;}
span.badge{
display:inline-block;
padding: 1px 5px 1px 5px;
text-align:center;
color:#fff !important;
font-size:10px;
line-height:13px;
/*-webkit-border-radius:3px;*/
-moz-border-radius:3px;
border-radius:3px;
-o-border-radius:3px;
-khtml-border-radius:3px;
}
a span.badge{
position: absolute;
top: -4px;
right: 0px;
margin: 0;
}
span.badge.on{
background-color:#f60;
color: #ffffff !important;
}
.lsub:nth-child(odd){background-color:#EFDEAB}
.lsub:nth-child(even){background-color:#EAD593;}
<div id="xx2menus">
<ul id="xx2menu">
<li>One</li>
<li>Two<span class="badge on">5</span></li>
<li>Three</li>
<li>Four<span class="badge on">17</span>
<ul>
<li class="lsub">Submenu1</li>
<li class="lsub">Submenu2</li>
</ul>
</li>
</ul>
</div>

Related

Second level submenu CSS

I was hoping if you can help me with my little problem. I am just updating one of my developers style sheets. I am a beginner in CSS so I am having difficulties adding the second level submenu in it.
Here's the link DEMO PAGE
This is my HTML
<div id="sidebar"><i class="icon icon-home"> </i>Dashboard<ul style="display: block;">
<li class="active"><i class="icon icon-home"></i> <span>Dashboard</span> </li>
<li> <i class="icon icon-signal"></i> <span>Charts & graphs</span> </li>
<li><i class="icon icon-th"></i> <span>Tables</span></li>
<li><i class="icon icon-fullscreen"></i> <span>Full width</span></li>
<li class="submenu"> <i class="icon icon-th-list"></i> <span>API</span> <span class="label label-important">4</span>
<ul>
<li>
boom
<ul>
</ul>
</li>
<li>% of National Roads Paved</li>
<li>Process</li>
<li>Regional Profiles</li>
</ul>
</li>
</ul>
</div>
and this is my CSS
/* Top user navigation */
#sidebar{ width:100%; background:#252125; position:absolute; clear:both; top:62px;}
#sidebar > ul{ margin:0px; padding:0px; width:100%; display:block; z-index:999;}
/*Border right sidebar */
#sidebar > ul > li { list-style-type:none; float:left; display:block; margin:0px; border-right:1px solid #464652; position:relative; padding:10px; cursor:pointer}
/*Border right */
#sidebar > ul > li a{ padding:12px 0;}
#sidebar > ul > li:hover ul { display:block;}
/*#sidebar > ul > li:hover { background-color:#41bedd;} */
/*On hover menu */
#sidebar > ul > li:hover { background-color:#464652;}
/*On hover menu */
#sidebar > ul > li:hover a{ background:none;}
/*Modules color */
#sidebar > ul li ul { margin:0px; padding:0px; display:none; z-index:999; position:absolute; left:0px; top:40px; background:#464652; min-width:200px;}
/*Modules color */
#sidebar > ul li ul li { list-style-type:none; margin:0px; font-size:12px;line-height:30px; }
#sidebar > ul li ul li a { display:block; padding:5px 10px; color:#fff; text-decoration:none; font-weight:bold; }
/*Modules color on hover */
#sidebar > ul li ul li:hover a{ background-color:#5A5A69;}
/*Modules color on hover*/
#sidebar > ul li span { cursor:pointer; margin:0px 2px 0 5px; font-weight:bold; color:#fff; font-size:11px; }
#sidebar > ul li a i{ background-image: url("../img/glyphicons-halflings-white.png"); margin-top:4px; vertical-align: top;}
I know this post has been posted from different threads. I really cant understand them. Hope you understand. Thanks in advance.
First of all, in your sample HTML, you don't have any lis in your tertiary level. Put some in there.
As for your CSS, it's presently set up to handle the showing and hiding of UL's below the top level one on hover. We need to get more specific so that it excludes the 3rd level--as well as then get more specific to and add a second level hover style.
Where you have this:
#sidebar > ul > li:hover ul { display:block;}
Change it to this:
#sidebar > ul > li:hover > ul { display:block;}
The first will show ALL child ULs of the LI on hover. The latter will show only the direct child of the LI on hover.
Now we need to add a trigger for the 3rd level:
#sidebar > ul > li > ul > li:hover > ul { display:block; top: 0; left: 200px}
While we're at it, we included a new set of positioning so that it appears to the right of the current hover rather than below (which would cover up the second level navigation.
Working example: http://jsfiddle.net/wS9t3/

Z-Indexed drop down menu not diplaying above a following div ul

I have added a second row on my menu_Box called menu_Box2
Trying my shot at Z-Indexing for the first time.
I cannot to get the menu_Box drop down menu to appear above menu_Box2 items.
Ive tried some different z-Index, overflow and position values with no luck.
I think I may need to Z-index some of the ul li items, but since they are group together its difficult for me to figure out which ones.
CSS:
#menu_Box{ /*MENU BOX CONTAINER*/
width: 890px;
height: 100%;
margin: 0 auto;
padding-left: 10px;
z-index:500
}
#menu_Box2{ /*MENU BOX CONTAINER*/
width: 890px;
height: 100%;
margin: 0 auto;
padding-left: 10px;
padding-top:6px;
overflow:visible;
}
#menu_Box ul,
#menu_Box2 ul{ /*MENU BOX STYLE*/
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
color:rgba(0, 57, 96, .95);
font-size:24px;
font-weight:normal;
padding:0 0 0 8px;
margin:0;
position:relative;
}
.extraStyle{
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
color:rgba(0, 57, 96, .85);
font-size:22px;
font-weight:normal;
padding:0 0 0 7px;
margin:0;
}
#menu_Box ul li,
#menu_Box2 ul li{
display:inline-block;
}
#menu_Box ul li:hover,
#menu_Box ul li a:hover,
#menu_Box2 ul li:hover,
#menu_Box2 ul li a:hover{
color:#456692;
text-decoration:none;
}
#menu_Box ul li a,visited,
#menu_Box2 ul li a,visited{
text-align:left;
color:#263A75;
display:block;
padding: 0 0 0 0; /*Padding between titles*/
text-decoration:none;
}
#menu_Box ul li:hover ul,
#menu_Box ul ul li,
#menu_Box2 ul li:hover ul,
#menu_Box2 ul ul li{
display:block;
}
#menu_Box ul ul,
#menu_Box2 ul ul{ /*Drop Down Box*/
border: 3px solid rgba(0, 57, 96, .85) ;
display:none;
position:absolute;
background-color: rgba(139, 183, 212, .9);
padding: 3px 5px 3px 5px; /*Padding between list items*/
}
#menu_Box ul ul li a,visited,
#menu_Box2 ul ul li a,visited{
color:#263A75;
}
#menu_Box ul ul li a:hover,
#menu_Box2 ul ul li a:hover{
color:#456692;
}
HTML:
<div id="menu_Box"> <!--Menu Box Div-->
<ul>
<li>Services
<ul>
<li>Psych-K </li>
<li>Food & Environmental Allergy and Sensitivity Testing </li>
<li>Supplement and Nutrition Evaluation </li>
<li>Food Value Testing </li>
</ul>
</li><span class="extraStyle">::</span>
<li>Sessions </li><span class="extraStyle">::</span>
<li>Biography </li><span class="extraStyle">::</span>
<li>Health Topics
<!-- <ul>
<li>Open Source Forums </li>
<li>Open Source Forums </li>
</ul>-->
</li><span class="extraStyle">::</span>
<li>Favorite Products</li><span class="extraStyle">::</span>
<li>Contact </li>
</ul>
</div> <!--Close Menu Box Div-->
<div id="menu_Box2"> <!--Menu Box Div-->
<ul>
<li>Recipies
</ul>
</div> <!--Close Menu Box Div-->
The z-index property only applies to positioned elements, so add position: relative; to your #menu_Box
Add z-index:500 to menu_Box ul not menuBox (I would use z-index 1, not z-index 500 because it is just enough to go above menu_Box2)
CSS:
#menu_Box ul
{
z-index:1;
}
This works because you need to add it to the 'popup-box', not the text.
DEMO

How to Set all children start with same line of main parent

I trying to build my own multi dropdown menu, and i encounter this problem and have to ideal how to solve it. The best i get is using margin-left:-100px but it will run out of alignment when dropdown more then level 2.
this is what i try to develop
and this is my BEST solution so far... but NOT what i want
this are my html code
<div id="menuBox">
<li class="mainMenu">home</li>
<li class="mainMenu">about</li>
<li class="mainMenu">product
<ul class="w200">
<li>money maker</li>
<li>personal coarch
<ul class="w200">
<li>1 to 1</li>
<li>1 to 5</li>
<li>1 to 10</li>
</ul>
</li>
</ul>
</li>
<li class="mainMenu">consult</li>
<li class="mainMenu">contact</li>
</div>
this is my CSS setting
li.mainMenu{
list-style:none;
display:inline-block;
padding:25px 35px;
border-top:1px solid #CCCDDD;
margin:0px;
font-size:1.3em;
background:#CCCCCC;
}
li{
background:#CCCCCC;
cursor:pointer;
}
ul{
float:left;
position:absolute;
z-index:999;
list-style:none;
}
ul>li{
padding:5px 20px;
}
So which/how should i modify my code?
First you need to change the div to ul since the li items are only allowed to be inside ul/ol elements.
Try with this CSS
#menuBox, #menuBox ul{ /*reset ul styling for menu/submenu*/
padding:0;
margin:0;
}
#menuBox{
white-space:nowrap;
list-style:none;
font-size:1.3em;
}
#menuBox > li{ /*first level li elements*/
display:inline-block;
padding:25px 35px;
border-top:1px solid #CCCDDD;
margin:0px;
}
#menuBox li{ /*all li elements*/
position:relative;
background:#CCCCCC;
cursor:pointer;
}
#menuBox li:hover{ /*hovered li elements*/
background:black;
color:white;
}
#menuBox li li{ /*sub li elements - all levels after 1st*/
color:black; /*hide all submenus*/
padding:5px 20px;
}
#menuBox li:hover > ul { /*submenu ul elements*/
display:block; /*show submenu when parent li is hovered*/
}
#menuBox ul{ /*all submenu ul elements*/
z-index:999;
list-style:none;
position:absolute;
top:80%;
left:50%;
border:1px solid black;
display:none;
}
Demo at http://jsfiddle.net/gaby/g6yX2/
it because in your li.mainMenu padding left is set to 35, remove it.
if you want to keep that padding:
HTML:
<li class="mainMenu"><label>product</label>
<ul class="w200">
<li><label>money maker</label></li>
<li><label>personal coarch</label>
<ul class="w200">
<li>1 to 1</li>
<li>1 to 5</li>
<li>1 to 10</li>
</ul>
</li>
</ul>
</li>
CSS:
li.mainMenu{
list-style:none;
display:inline-block;
padding:25px 0px;
border-top:1px solid #CCCDDD;
margin:0px;
font-size:1.3em;
background:#CCCCCC;
}
li.mainMenu label {
padding: 0px 35px;
}
Example: http://jsfiddle.net/RaPK9/

trying to center a css menu made on purecssmenu.com

i have a menu that i generated on purecssmenu.com and im having trouble trying to center it on my page here is the code...
<!-- Start PureCSSMenu.com STYLE -->
<style>
#pcm{display:none;}
ul.pureCssMenu ul{display:none}
ul.pureCssMenu li:hover>ul{display:block}
ul.pureCssMenu ul{position: absolute;left:-1px;top:98%;}
ul.pureCssMenu ul ul{position: absolute;left:98%;top:-2px;}
ul.pureCssMenu,ul.pureCssMenu ul {
margin:0px;
list-style:none;
padding:0px 2px 2px 0px;
background-color:#000000;
background-repeat:repeat;
border-color:#000000;
border-width:1px;
border-style:solid;
}
ul.pureCssMenu table {border-collapse:collapse}ul.pureCssMenu {
display:block;
zoom:1;
float: left;
}
ul.pureCssMenu ul{
width:80.85000000000001px;
}
ul.pureCssMenu li{
display:block;
margin:2px 0px 0px 2px;
font-size:0px;
}
ul.pureCssMenu a:active, ul.pureCssMenu a:focus {
outline-style:none;
}
ul.pureCssMenu a, ul.pureCssMenu li.dis a:hover, ul.pureCssMenu li.sep a:hover {
display:block;
vertical-align:middle;
background-color:#000000;
border-width:1px;
border-color:#000000;
border-style:solid;
text-align:left;
text-decoration:none;
padding:2px 5px 2px 10px;
_padding-left:0;
font:11px Arial;
color: #969696;
text-decoration:none;
cursor:default;
}
ul.pureCssMenu span{
overflow:hidden;
}
ul.pureCssMenu li {
float:left;
}
ul.pureCssMenu ul li {
float:none;
}
ul.pureCssMenu ul a {
text-align:left;
white-space:nowrap;
}
ul.pureCssMenu li.sep{
text-align:left;
padding:0px;
line-height:0;
height:100%;
}
ul.pureCssMenu li.sep span{
float:none; padding-right:0;
width:3px;
height:100%;
display:inline-block;
background-color:#cccccc #111111 #111111 #cccccc; background-image:none;}
ul.pureCssMenu ul li.sep span{
width:100%;
height:3px;
}
ul.pureCssMenu li:hover{
position:relative;
}
ul.pureCssMenu li:hover>a{
background-color:#000000;
border-color:#000000;
border-style:solid;
font:11px Arial;
color: #ffa500;
text-decoration:none;
}
ul.pureCssMenu li a:hover{
position:relative;
background-color:#000000;
border-color:#000000;
border-style:solid;
font:11px Arial;
color: #ffa500;
text-decoration:none;
}
ul.pureCssMenu li.dis a {
color: #666 !important;
}
ul.pureCssMenu img {border: none;float:left;_float:none;margin-right:2px;width:16px;
height:16px;
}
ul.pureCssMenu ul img {width:16px;
height:16px;
}
ul.pureCssMenu img.over{display:none}
ul.pureCssMenu li.dis a:hover img.over{display:none !important}
ul.pureCssMenu li.dis a:hover img.def {display:inline !important}
ul.pureCssMenu li:hover > a img.def {display:none}
ul.pureCssMenu li:hover > a img.over {display:inline}
ul.pureCssMenu a:hover img.over,ul.pureCssMenu a:hover ul img.def,ul.pureCssMenu a:hover a:hover img.over{display:inline}
ul.pureCssMenu a:hover img.def,ul.pureCssMenu a:hover ul img.over,ul.pureCssMenu a:hover a:hover img.def{display:none}
ul.pureCssMenu a:hover ul{display:block}
ul.pureCssMenu span{
display:block;
background-image:url(./images/arr_white.gif);
background-position:right center;
background-repeat: no-repeat;
padding-right:12px;}
ul.pureCssMenu li:hover>a>span{ background-image:url(./images/arrv_white.gif);
}
ul.pureCssMenu a:hover span{ _background-image:url(./images/arrv_white.gif)}
ul.pureCssMenu ul span,ul.pureCssMenu a:hover table span{background-image:url(./images/arr_white.gif)}
</style>
<!-- End PureCSSMenu.com STYLE -->
and here is the html, witch is probably not even needed in this posted but i figure i would include it.. i just want that menu centered inside my website.
<!-- Start PureCSSMenu.com MENU -->
<ul class="pureCssMenu pureCssMenum">
<li class="pureCssMenui"><a class="pureCssMenui" href="home.html" target="scare">home</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">about</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#"><span>haunts</span><![if gt IE 6]></a><![endif]><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="pureCssMenum">
<li class="pureCssMenui"><a class="pureCssMenui" href="#">2009</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">2010</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">2011</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">2012</a></li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">studio</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#"><span>products</span><![if gt IE 6]></a><![endif]><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="pureCssMenum">
<li class="pureCssMenui"><a class="pureCssMenui" href="#">nightmares</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">hauntworks</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">atmosfears</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">frightwears</a></li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#"><span>links</span><![if gt IE 6]></a><![endif]><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="pureCssMenum">
<li class="pureCssMenui"><a class="pureCssMenui" href="#">haunts</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">suppliers</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">resources</a></li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">contact</a></li>
</ul>
<a id="pcm" href="http://www.purecssmenu.com/">CSS Drop Down Menu by PureCSSMenu.com</a>
<!-- End PureCSSMenu.com MENU -->
thanks in advance for your time.
Surround it with a div and then center the div.
<div class="table">
Then add the following to your css
.table {
display: table; /* Allow the centering to work */
margin: 0 auto;
}
See the working example.
http://jsfiddle.net/uh2Jt/3/
ul.pureCssMenu,ul.pureCssMenu ul {
margin:0 auto;
}
Here's one solution. The issue I found was that the .pureCssMenu was being floated left. I just overwrote that so you can see where it was happening. Probably a better idea to edit the css properly though, if you don't understand let me know and I'll explain more. Also wrapped it in a div (.centerme) with text-align: center;
http://jsfiddle.net/nYbcW/
.centerme{
text-align: center;
}
ul.pureCssMenu {
float: none !important;
display: inline-block !important;
text-align:center
}
Just setting:
ul.pureCssMenu,ul.pureCssMenu ul {
margin:0 auto;
}
won't work since it looks like the menu's position is set to absolute. Instead of messing with the menu's code, you can just put it in a wrapper div like so :
<div class="menuWrapper">
all the html for the menu
</div>
and then using this CSS, with whatever width works for you:
.menuWrapper{
margin: 0 auto;
width: 400px;
}
Check out the example here: http://jsfiddle.net/mCmfU/
This is the simplest you can get:
ul.pureCssMenu,ul.pureCssMenu ul {
margin:0 auto;
float: none;
height: 25px;
width: 25%;
}
Just adjust the width and the height to your need.
Note: you can add this bit of code to the bottom of you styles so you don't need to bother searching for it.

Strange CSS behavior

Sorry for the length of the post. This is quite a weird problem and I want to give as much info as possible.
I have the following css rules I am using for a horizontal navigation menu. The menu is created using ASP:repeaters and a database table of items.
#nav
{
margin: 0px;
padding:0px;
list-style-type: none;
height: 20px;
margin-right:auto;
margin-left:auto;
width:726px;
}
#nav > li
{
margin:0px;
padding:0px;
display:inline-block;
color: #FFFFFF;
height:17px;
border:0px;
width:90.75px;
text-align:center;
position:relative;
float:left;
}
#nav > li > ul
{
margin:0px;
padding:0px;
position: absolute;
left: -999em;
display:block;
overflow:visible;
z-index:100;
width:150px;
background-color:#eee;
}
#nav > li:hover > ul
{
left:0px;
z-index:100;
box-shadow: 0px 0px 5px #555;
-moz-box-shadow: 0px 0px 5px #555;
-webkit-box-shadow: 0px 0px 5px #555;
/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
/* IE 5-7 */
filter: alpha(opacity=80);
/* Netscape */
-moz-opacity: 0.8;
/* Safari 1.x */
-khtml-opacity: 0.8;
/* Good browsers */
opacity: 0.8;
}
#nav > li > ul > li
{
left:0px;
display:block;
color:#333;
width:150px;
text-align:left;
height:auto;
}
#nav a, #navbottom a
{
line-height:20px;
display:block;
height:20px;
border-bottom:2px solid #0c1b53;
}
#nav a:link, #navbottom a:link, #nav a:visited, #navbottom a:visited
{
border-bottom:2px solid #0c1b53;
color: #FFFFFF;
text-decoration: none;
}
#nav a:hover, #navbottom a:hover
{
border-bottom:2px solid #fff;
}
#nav a:active, #navbottom a:active
{
border-bottom:2px solid #fff;
color: #FEFFBD;
text-decoration: none;
}
#nav > li > ul > li a:link
{
margin:10px;
line-height:15px;
height:auto;
color:#444;
border-bottom: 1px solid #777;
/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
/* IE 5-7 */
filter: alpha(opacity=100);
/* Netscape */
-moz-opacity: 1.0;
/* Safari 1.x */
-khtml-opacity: 1.0;
/* Good browsers */
opacity: 1.0;
}
#nav > li > ul > li a:hover
{
color:#222;
border-bottom: 1px solid #555;
}
The HTML it produces is below:
<ul id="nav">
<li>
<input type="hidden" name="ctl00$TopNavRepeat$ctl01$LinkIdField1" id="ctl00_TopNavRepeat_ctl01_LinkIdField1" value="1" />
<a id="ctl00_TopNavRepeat_ctl01_HyperLink1" title="Home Page" href="../default.aspx">Home </a>
<ul></ul>
</li>
<li>
<input type="hidden" name="ctl00$TopNavRepeat$ctl02$LinkIdField1" id="ctl00_TopNavRepeat_ctl02_LinkIdField1" value="10" />
<a id="ctl00_TopNavRepeat_ctl02_HyperLink1" title="News from the IMA" href="../news/list.aspx">News </a>
<ul></ul>
</li>
<li>
<input type="hidden" name="ctl00$TopNavRepeat$ctl03$LinkIdField1" id="ctl00_TopNavRepeat_ctl03_LinkIdField1" value="11" />
<a id="ctl00_TopNavRepeat_ctl03_HyperLink1" title="About the IMA" href="../organisation/history.aspx">Organisation </a>
<ul>
<li><a id="ctl00_TopNavRepeat_ctl03_DropDownList_ctl01_HyperLink1" title="about the IMA" class="dropdown_Item" href="../organisation/history.aspx">About </a>
</li>
<li><a id="ctl00_TopNavRepeat_ctl03_DropDownList_ctl02_HyperLink1" title="This is a description" class="dropdown_Item" href="list.aspx?type=all">Members </a>
</li>
<li><a id="ctl00_TopNavRepeat_ctl03_DropDownList_ctl03_HyperLink1" class="dropdown_Item" href="../Boats/list.aspx#">Boats</a>
</li>
</ul>
</li>
<li>
<input type="hidden" name="ctl00$TopNavRepeat$ctl06$LinkIdField1" id="ctl00_TopNavRepeat_ctl06_LinkIdField1" value="14" />
<a id="ctl00_TopNavRepeat_ctl06_HyperLink1" href="../adverts">Ads </a>
<ul>
<li><a id="ctl00_TopNavRepeat_ctl06_DropDownList_ctl01_HyperLink1" title="All For Sale Items" class="dropdown_Item" href="../adverts/list.aspx?type=sale">For Sale </a>
</li>
<li><a id="ctl00_TopNavRepeat_ctl06_DropDownList_ctl02_HyperLink1" title="All Wanted Items" class="dropdown_Item" href="../adverts/list.aspx?type=wanted">Wanted </a>
</li>
<li><a id="ctl00_TopNavRepeat_ctl06_DropDownList_ctl03_HyperLink1" title="Advertise with the IMA" class="dropdown_Item" href="../adverts/edit.aspx?action=New">Post an Ad </a>
</li>
</ul>
</li>
</ul>
The Menu this produces (some list items have been omitted for shortness) is below. Despite the two item "Organisation" and "Ads" each having three child items and despite each child item seeming to be identical the second item in organisation displays with the rules for nav > li a instead of nav > li > ul > li a.
As the menu displays http://dl.dropbox.com/u/4913815/Untitled.png
I've been going through it and as far as i cant tell what is happening. Can anyone explain this?
There is no #nav > li > ul > li a:visited or active rules defined. The members link is taking information from the #nav a:active instead and so displaying incorrectly.
Changing #nav > li > ul > li a:link to #nav > li > ul > li a:link, #nav > li > ul > li a:visited, #nav > li > ul > li a:active fixes this issue

Resources