CSS dropdown menu element moving to left? - html

I'm having some troubles with this css menu of mine (I'm pretty new to the whole HTML/CSS thing, and so I pieced together some code from Wordpress and other websites). Everything works fine, except when the following occurs:
I hover over a menu item
The dropdown menu fades in
I move my cursor out of the dropdown menu
It moves to the very left side of the menu element and fades out
I don't understand why it moves to the left and doesn't stay in its intended position, and I need some help getting rid of it.
Here's the CSS code:
#import url(http://fonts.googleapis.com/css?family=Droid+Serif);
#cssmenu {clear: both; padding: 0; display: block; margin: 0; border: 0; float: left; z-index: 99999;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding-left: 0;}
#cssmenu ul {position: relative; z-index: 99999; }
#cssmenu ul li { float: left; min-height: 1px; vertical-align: middle;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 99999; cursor: default; opacity: 1;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 99999; width: 100%;}
#cssmenu ul ul li {float: none;}
#cssmenu ul ul ul {top: 0; left: auto; right: -99.5%; }
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0; }
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; line-height: 1em; text-decoration: none; }
#cssmenu {
position: fixed;
top: 0;
left: 180px;
width:100%;
background: #020202;
border-bottom: 4px solid #08c1c3;
font-family: 'Droid Serif', serif;
font-size: 14px;
}
#cssmenu > ul { *display: inline-block; }
#cssmenu:after, #cssmenu ul:after {
content: '';
display: block;
clear: both;
}
#cssmenu a {
display: block;
background: #020202;
color: #CCC;
opacity: 1;
padding: 0 20px;
z-index: 99999;
}
#cssmenu ul ul {
border-top: 4px solid #08c1c3;
text-transform: none;
min-width: 190px;
float: left;
opacity: 0;
position: absolute;
left: 0;
visibility: hidden;
-webkit-transition: visibility 0s 0.4s, opacity 0.4s ease-in;
-moz-transition: visibility 0s 0.4s, opacity 0.4s ease-in;
-o-transition: visibility 0s 0.4s, opacity 0.4s ease-in;
transition: visibility 0s 0.4s, opacity 0.4s ease-in;
z-index: 99999;
}
#cssmenu ul ul a {
background: #020202;
color: #CCC;
border: 1px solid #08c1c3;
border-top: 0 none;
line-height: 1.25;
padding: 16px 20px;
z-index: 99999;
width: 150px;
}
#cssmenu ul li:hover > ul {
display: block;
opacity: 1;
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
transition: opacity 0.4s ease-in;
visibility: visible;
}
#cssmenu ul ul li {
}
#cssmenu > ul > li > a { line-height: 48px; }
/* #cssmenu ul ul li:first-child > a { border-top: 1px solid #08c1c3; }
#cssmenu ul ul li:hover > a { background: #333; } */
#cssmenu ul ul li:last-child > a {
box-shadow: 0 1px 0 #08c1c3;
}
#cssmenu ul li:hover > a, #cssmenu ul li.active > a {
background: #333;
color: #08c1c3;
opacity: 1;
} /* Top level of menu */
#cssmenu ul li.has-sub > a:after {
content: "\00BB";
float: right;
margin-left: 5px;
}
#cssmenu ul li.last ul {
left: auto;
right: 0;
}
#cssmenu ul li.last ul ul {
left: auto;
right: 99.5%;
}
And here's an example menu:
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'>Home</a></li>
<li class='has-sub '><a href='#'>A</a>
<ul>
<li><a href='#'>A-a</a></li>
<li><a href='#'>A-b</a></li>
</ul>
</li>
<li class='has-sub '><a href='#'>B</a>
<ul>
<li><a href='#'>B-a</a></li>
<li><a href='#'>B-b</a></li>
<li><a href='#'>B-c</a></li>
</ul>
</li>
<li><a href='#'>C</a></li>
<li><a href='#'>About</a></li>
</ul>
</div>

You need to set position:relative on the list items for the default state, not for the hover state:
#cssmenu ul li {
position: relative;
}
Otherwise when you hover out the sub-menu is positioned relative to the menu container and not its parent
Updated fiddle

Related

Creating submenu in nav menu

I want to create submenu in my nav menu. i have little knowledge of css.
but facing some prob.
when i add submenu into nav menu. menu shows as ul li,direct ally.
#cssmenu {
background: #88BC18;
width: auto;
z-index: 1;
position: relative;
}
#cssmenu ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
zoom: 1;
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0;
margin: 0;
}
#cssmenu.align-right ul li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu ul li a {
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color 25s;
-o-transition: color .25s;
transition: color .25s;
}
#cssmenu ul li a:hover {
color: #004900;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #004900;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width 25s;
-o-transition: width .25s;
transition: width .25s;
}
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #ffffff;
opacity: .5;
}
#cssmenu ul li.last>a:after,
#cssmenu ul li:last-child>a:after {
display: none;
}
#cssmenu ul li.active a {
color: #004900;
}
#cssmenu ul li.active a:before {
width: 100%;
}
#cssmenu.align-right li.last>a:after,
#cssmenu.align-right li:last-child>a:after {
display: block;
}
#cssmenu.align-right li:first-child a:after {
display: none;
}
<div id="navWrap">
<nav class="nav">
<div id="cssmenu" class="centered">
<ul>
<li class='first'><span>Home</span></li>
<li><span>Features</span></li>
<li><span>About</span></li>
<li><span>Prices</span></li>
<li><span>F.A.Q</span></li>
<li><span>How to Use</span></li>
<li><span>Contact</span></li>
<li><span>Log In</span></li>
<li class="last"><span>Help</span></li>
</ul>
</div>
</nav>
</div>
This should help you get started. Added css for submenu.
Check the About Link now.
#cssmenu {
background: #88BC18;
width: auto;
z-index: 1;
position: relative;
}
#cssmenu ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
zoom: 1;
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0;
margin: 0;
}
#cssmenu.align-right ul li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu ul li a {
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color 25s;
-o-transition: color .25s;
transition: color .25s;
}
#cssmenu ul li a:hover {
color: #004900;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #004900;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width 25s;
-o-transition: width .25s;
transition: width .25s;
}
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #ffffff;
opacity: .5;
}
#cssmenu ul li.last>a:after,
#cssmenu ul li:last-child>a:after {
display: none;
}
#cssmenu ul li.active a {
color: #004900;
}
#cssmenu ul li.active a:before {
width: 100%;
}
/* New CSS for Sub Menu */
#cssmenu ul li {
position: relative;
}
#cssmenu ul ul {
position: absolute;
top: 100%;
left: 0;
background: #88BC18;
display: none;
}
#cssmenu ul li:hover ul {
display: block;
}
#cssmenu ul ul li a {
white-space: nowrap;
}
<div id="navWrap">
<nav class="nav">
<div id="cssmenu" class="centered">
<ul>
<li class='first'><span>Home</span></li>
<li><span>Features</span></li>
<li><span>About</span>
<ul>
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
</ul>
</li>
<li><span>Prices</span></li>
</ul>
</div>
</nav>
I've added the second item in menu to add a submenu in it and added two selector on the bottom of css. Here is the sample
HTML
<div id="navWrap">
<nav class="nav">
<div id="cssmenu" class="centered">
<ul>
<li class='first'><span>Home</span></li>
<li><span>Have submenu</span>
<ul class="submenu">
<li>submenu one</li>
<li>submenu two</li>
</ul>
</li>
<li><span>About</span></li>
<li><span>Prices</span></li>
<li><span>F.A.Q</span>
</li>
<li><span>How to Use</span></li>
<li><span>Contact</span></li>
<li><span>Log In</span></li>
<li class="last"><span>Help</span></li>
</ul>
</div>
</nav>
</div>
CSS
#cssmenu {background: #88BC18;width: auto;z-index: 1; position: relative;}
#cssmenu ul {list-style: none; margin: 0; padding: 0; line-height: 1; display: block; zoom: 1; }
#cssmenu ul:after {content: " ";display: block;font-size: 0;height: 0; clear: both;visibility: hidden;}
#cssmenu ul li { display: inline-block;padding: 0;margin: 0;}
#cssmenu.align-right ul li {float: right;}
#cssmenu.align-center ul {text-align: center;}
#cssmenu ul li a {color: #ffffff;text-decoration: none;display: block; padding: 15px 25px;font-family: 'Open Sans', sans-serif;font-weight: 700; text-transform: uppercase;font-size: 14px;position: relative;-webkit-transition: color .25s;-moz-transition: color .25s;-ms-transition: color 25s;-o-transition: color .25s;transition: color .25s;}
#cssmenu ul li a:hover {color: #004900;}
#cssmenu ul li a:hover:before {width: 100%;}
#cssmenu ul li a:before {content: "";display: block;position: absolute; left: 0;bottom: 0; height: 3px;width: 0;background: #004900;-webkit-transition: width .25s;-moz-transition: width .25s;-ms-transition: width 25s; -o-transition: width .25s;transition: width .25s;}
#cssmenu ul li a:after {content: "";display: block;position: absolute; right: -3px; top: 19px;height: 6px; width: 6px;background: #ffffff;opacity: .5;}
#cssmenu ul li.last > a:after,
#cssmenu ul li:last-child > a:after {display: none;}
#cssmenu ul li.active a {color: #004900;}
#cssmenu ul li.active a:before {width: 100%;}
#cssmenu.align-right li.last > a:after,
#cssmenu.align-right li:last-child > a:after {display: block;}
#cssmenu.align-right li:first-child a:after {display: none;}
#cssmenu .submenu{
display:none;
}
#cssmenu li:hover > ul{
display:block;
width:200px;
z-index: 10;
position: absolute;
left: 100px;
top: 44px;
background: #88BC18;
}

How do i add dropdown items to my horizontal menu bar?

hi i am trying to add a drop down item to my horizontal menu bar. i would like the drop down item to be "Parish council minutes" under "parish council information" like these but in my styles:
(http://www2.psd100.com/wp-content/uploads/2013/03/web-dropdown-menu-bar-psd0306.jpg)
i also intend to add a few more drop down menu item in different locations.
many thank in advance.
my css:
my css:
#cssmenu {
background: #f96e5b;
width: 1404px;
margin-right:auto;
margin-left:auto;
padding:0;
}
#cssmenu ul {
list-style: none;
margin: 0%;
padding: 0%;
line-height: 1;
display: block;
zoom: 1;
width:100%
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0%;
height: 0%;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0%;
margin: 0%;
}
#cssmenu.align-right ul li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu ul li a {
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color .25s;
-o-transition: color .25s;
transition: color .25s;
}
#cssmenu ul li a:hover {
color: #333333;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #ffffff;
opacity: .5;
}
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #333333;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width .25s;
-o-transition: width .25s;
transition: width .25s;
}
#cssmenu ul li.last > a:after,
#cssmenu ul li:last-child > a:after {
display: none;
}
#cssmenu ul li.active a {
color: #333333;
}
#cssmenu ul li.active a:before {
width: 100%;
}
#cssmenu.align-right li.last > a:after,
#cssmenu.align-right li:last-child > a:after {
display: block;
}
#cssmenu.align-right li:first-child a:after {
display: none;
}
#media screen and (max-width: 100%) {
#cssmenu ul li {
float: none;
display: block;
}
#cssmenu ul li a {
width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-bottom: 1px solid #fb998c;
}
#cssmenu ul li.last > a,
#cssmenu ul li:last-child > a {
border: 0;
}
#cssmenu ul li a:after {
display: none;
}
#cssmenu ul li a:before {
display: none;
}
}
#menubar2 {
width:400px;
margin-left:auto;
margin-right:auto;
}
my html:
<div id='cssmenu'>
<ul>
<li class='active'>
<li>Home</li>
<li>Parish Council information</li>
<li>What's on </li>
<li>History</li>
<li>Churches</li>
<li>Newsletter</li>
<li>Village Halls and Social Clubs </li>
<li>Gallery</li>
<div id="menubar2">
<li>Business in Runtons</li>
<li>Contact us</li>
</div>
</ul>
</div>
Put your "flyouts" (lets call it like this cause thats what is is) into your LI's.
Like this:
HTML:
<ul> <!-- this is your horizontal menu bar ul -->
<li>
Some Page
<div class="flyout_container">
<ul>
<li>Some Subpage of Some page
</ul>
</div>
</li>
</ul>
CSS:
ul > li
{
display:block;
position:relative;
height:30px;
}
ul > li .flyout_container
{
position:absolute;
top:30px; /* this is the LI's height*/
left:0;
display:none;
}
ul > li:hover .flyout_container
{
display:block;
}
Normal state you just see the first level and once u hover an LI with a flyout_container in it, it will appear located as you wished on the given screenshot.

Align responsive css menu to middle without altering it in mobile resolution

I'm trying to align a menu on the center. The only problem is that it's a responsive menu and it shrunks ugly when in mobile resolution.
I tried with text-align=center in the div, I tried putting it inside a table and about everything I could find online, so I'm guessing it's something I'm doing wrong at this point.
Here is the actual menu:
<div id='cssmenu'>
<ul>
<li class="active"></img> ACASÄ‚</li>
<li class='has-sub'></img> PRODUSE
<ul>
<li class='has-sub'><a href='#'>Product 1</a>
<ul>
<li><a href='#'>Sub Product</a></li>
<li><a href='#'>Sub Product</a></li>
</ul>
</li>
<li class='has-sub'><a href='#'>Product 2</a>
<ul>
<li><a href='#'>Sub Product</a></li>
<li><a href='#'>Sub Product</a></li>
</ul>
</li>
</ul>
</li>
<li></img> CONTACT</li>
</ul>
</div>
Nothing hew there, but here's the 2 mile long menu css.
I'm sure I didn't have to post all the following css story, but perhaps it's something I'm overlooking.
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a,
#cssmenu #menu-button {
margin: 0;
padding: 0;
border: 0;
list-style: none;
line-height: 1;
display: block;
position: relative;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#cssmenu:after,
#cssmenu > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#cssmenu #menu-button {
display: none;
}
#cssmenu {
width: auto;
font-family: 'Open Sans', sans-serif;
line-height: 1;
background: #ffffff;
}
#menu-line {
position: absolute;
top: 0;
left: 0;
height: 3px;
/*background: #009ae1;*/
background: #008000;
-webkit-transition: all 0.25s ease-out;
-moz-transition: all 0.25s ease-out;
-ms-transition: all 0.25s ease-out;
-o-transition: all 0.25s ease-out;
transition: all 0.25s ease-out;
}
#cssmenu > ul > li {
float: left;
}
#cssmenu.align-center > ul {
font-size: 0;
text-align: center;
}
#cssmenu.align-center > ul > li {
display: inline-block;
float: none;
}
#cssmenu.align-center ul ul {
text-align: left;
}
#cssmenu.align-right > ul > li {
float: right;
}
#cssmenu.align-right ul ul {
text-align: right;
}
#cssmenu > ul > li > a {
padding: 20px;
font-size: 20px;
text-decoration: none;
text-transform: uppercase;
color: #000000;
-webkit-transition: color .2s ease;
-moz-transition: color .2s ease;
-ms-transition: color .2s ease;
-o-transition: color .2s ease;
transition: color .2s ease;
}
#cssmenu > ul > li:hover > a,
#cssmenu > ul > li.active > a {
/*color: #009ae1;*/
color: #008000;
}
#cssmenu > ul > li.has-sub > a {
padding-right: 25px;
}
#cssmenu > ul > li.has-sub > a::after {
position: absolute;
top: 21px;
right: 10px;
width: 4px;
height: 4px;
border-bottom: 1px solid #000000;
border-right: 1px solid #000000;
content: "";
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: border-color 0.2s ease;
-moz-transition: border-color 0.2s ease;
-ms-transition: border-color 0.2s ease;
-o-transition: border-color 0.2s ease;
transition: border-color 0.2s ease;
}
#cssmenu > ul > li.has-sub:hover > a::after {
/*border-color: #009ae1;*/
border-color: #008000;
}
#cssmenu ul ul {
position: absolute;
left: -9999px;
}
#cssmenu li:hover > ul {
left: auto;
}
#cssmenu.align-right li:hover > ul {
right: 0;
}
#cssmenu ul ul ul {
margin-left: 100%;
top: 0;
}
#cssmenu.align-right ul ul ul {
margin-left: 0;
margin-right: 100%;
}
#cssmenu ul ul li {
height: 0;
-webkit-transition: height .2s ease;
-moz-transition: height .2s ease;
-ms-transition: height .2s ease;
-o-transition: height .2s ease;
transition: height .2s ease;
}
#cssmenu ul li:hover > ul > li {
height: 32px;
}
#cssmenu ul ul li a {
padding: 10px 20px;
width: 160px;
font-size: 12px;
background: #333333;
text-decoration: none;
color: #dddddd;
-webkit-transition: color .2s ease;
-moz-transition: color .2s ease;
-ms-transition: color .2s ease;
-o-transition: color .2s ease;
transition: color .2s ease;
}
#cssmenu ul ul li:hover > a,
#cssmenu ul ul li a:hover {
color: #ffffff;
}
#cssmenu ul ul li.has-sub > a::after {
position: absolute;
top: 13px;
right: 10px;
width: 4px;
height: 4px;
border-bottom: 1px solid #dddddd;
border-right: 1px solid #dddddd;
content: "";
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: border-color 0.2s ease;
-moz-transition: border-color 0.2s ease;
-ms-transition: border-color 0.2s ease;
-o-transition: border-color 0.2s ease;
transition: border-color 0.2s ease;
}
#cssmenu.align-right ul ul li.has-sub > a::after {
right: auto;
left: 10px;
border-bottom: 0;
border-right: 0;
border-top: 1px solid #dddddd;
border-left: 1px solid #dddddd;
}
#cssmenu ul ul li.has-sub:hover > a::after {
border-color: #ffffff;
}
#media all and (max-width: 768px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) {
#cssmenu {
width: 100%;
}
#cssmenu ul {
width: 100%;
display: none;
}
#cssmenu.align-center > ul,
#cssmenu.align-right ul ul {
text-align: left;
}
#cssmenu ul li,
#cssmenu ul ul li,
#cssmenu ul li:hover > ul > li {
width: 100%;
height: auto;
border-top: 1px solid rgba(120, 120, 120, 0.15);
}
#cssmenu ul li a,
#cssmenu ul ul li a {
width: 100%;
}
#cssmenu > ul > li,
#cssmenu.align-center > ul > li,
#cssmenu.align-right > ul > li {
float: none;
display: block;
}
#cssmenu ul ul li a {
padding: 20px 20px 20px 30px;
font-size: 12px;
color: #000000;
background: none;
}
#cssmenu ul ul li:hover > a,
#cssmenu ul ul li a:hover {
color: #000000;
}
#cssmenu ul ul ul li a {
padding-left: 40px;
}
#cssmenu ul ul,
#cssmenu ul ul ul {
position: relative;
left: 0;
right: auto;
width: 100%;
margin: 0;
}
#cssmenu > ul > li.has-sub > a::after,
#cssmenu ul ul li.has-sub > a::after {
display: none;
}
#menu-line {
display: none;
}
#cssmenu #menu-button {
display: block;
padding: 20px;
color: #000000;
cursor: pointer;
font-size: 12px;
text-transform: uppercase;
}
#cssmenu #menu-button::after {
content: '';
position: absolute;
top: 20px;
right: 20px;
display: block;
width: 15px;
height: 2px;
background: #000000;
}
#cssmenu #menu-button::before {
content: '';
position: absolute;
top: 25px;
right: 20px;
display: block;
width: 15px;
height: 3px;
border-top: 2px solid #000000;
border-bottom: 2px solid #000000;
}
#cssmenu .submenu-button {
position: absolute;
z-index: 10;
right: 0;
top: 0;
display: block;
border-left: 1px solid rgba(120, 120, 120, 0.15);
height: 52px;
width: 52px;
cursor: pointer;
}
#cssmenu .submenu-button::after {
content: '';
position: absolute;
top: 21px;
left: 26px;
display: block;
width: 1px;
height: 11px;
background: #000000;
z-index: 99;
}
#cssmenu .submenu-button::before {
content: '';
position: absolute;
left: 21px;
top: 26px;
display: block;
width: 11px;
height: 1px;
background: #000000;
z-index: 99;
}
#cssmenu .submenu-button.submenu-opened:after {
display: none;
}
}
Here's the fiddle. I hid your drop-down and images since they aren't needed for the example. Here are the two important rules:
ul {
display: block;
text-align: center;
}
li {
display: inline-block;
}
This will now add all items from the center and create space out. Make sure to note that inline-block elements have a hidden margin (space) so if you want them right next to each other, you'll need to create a negative margin on the li.
Wrap these new rules in a min-width media query if you don't want it to mess up your mobile styling.

Dropdown menu hiding behind slideshow

I have an issue related to dropdown menu that remains behind Lean Slider. Please help me how to fix this issue. I am pasting html and css code here that you see where there is a problem.
I have tried to change z-index, but nothing changed.
HTML:
<pre><div id='cssmenu'>
<ul>
<li class='has-sub'><a href='#'>About us</a>
<ul>
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
</ul>
</li>
<li class='has-sub'><a href='#'>Programs</a>
<ul>
<li>Submenu</li>
<li class='has-sub'><a href='#'>Submenu</a>
<ul>
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
<li>Submenu</li>
</ul>
</li>
<li>Submenu</li>
</ul>
</li>
<li>News</li>
<li>Network</li>
<li>Press</li>
<li class='last'>Contact us</li>
</ul>
</div><code>
I am also pasting CSS code here.
<pre>#cssmenu {
position: relative;
height: auto;
background: #2b2f3a;
width: auto;
}
#cssmenu ul {
list-style: none;
padding: 0;
margin: 0;
line-height: 1;
}
#cssmenu > ul {
position: relative;
display: block;
background: #fff;
width: 100%;
z-index: 500;
}
#cssmenu:after,
#cssmenu > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#cssmenu.align-right > ul > li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu.align-center ul ul {
text-align: left;
}
#cssmenu > ul > li {
display: inline-block;
position: relative;
margin: 0;
padding: 0;
}
#cssmenu > ul > #menu-button {
display: none;
}
#cssmenu ul li a {
display: block;
font-family: Helvetica, sans-serif;
text-decoration: none;
}
#cssmenu > ul > li > a {
font-size: 12px;
font-weight: bold;
padding: 17px 12px;
color: #559c00;
text-transform: uppercase;
-webkit-transition: color 0.25s ease-out;
-moz-transition: color 0.25s ease-out;
-ms-transition: color 0.25s ease-out;
-o-transition: color 0.25s ease-out;
transition: color 0.25s ease-out;
}
#cssmenu > ul > li.has-sub > a {
padding-right: 32px;
}
#cssmenu > ul > li:hover > a {
color: #72cc00;
}
#cssmenu li.has-sub::after {
display: block;
content: "";
position: absolute;
width: 0;
height: 0;
}
#cssmenu > ul > li.has-sub::after {
right: 15px;
top: 20px;
border: 5px solid transparent;
border-top-color: #559c00;
}
#cssmenu > ul > li:hover::after {
border-top-color: #ffffff;
}
#indicatorContainer {
position: absolute;
height: 12px;
width: 100%;
bottom: 0px;
overflow: hidden;
z-index: -1;
}
#pIndicator {
position: absolute;
height: 0;
width: 100%;
border: 12px solid transparent;
border-top-color: #2b2f3a;
z-index: -2;
-webkit-transition: left .25s ease;
-moz-transition: left .25s ease;
-ms-transition: left .25s ease;
-o-transition: left .25s ease;
transition: left .25s ease;
}
#cIndicator {
position: absolute;
height: 0;
width: 100%;
border: 12px solid transparent;
border-top-color: #2b2f3a;
top: -12px;
right: 100%;
z-index: -2;
}
#cssmenu ul ul {
position: absolute;
left: -9999px;
top: 70px;
opacity: 0;
-webkit-transition: opacity .3s ease, top .25s ease;
-moz-transition: opacity .3s ease, top .25s ease;
-ms-transition: opacity .3s ease, top .25s ease;
-o-transition: opacity .3s ease, top .25s ease;
transition: opacity .3s ease, top .25s ease;
z-index: 1000;
}
#cssmenu ul ul ul {
top: 37px;
padding-left: 5px;
}
#cssmenu ul ul li {
position: relative;
}
#cssmenu > ul > li:hover > ul {
left: auto;
top: 44px;
opacity: 1;
}
#cssmenu.align-right > ul > li:hover > ul {
left: auto;
right: 0;
opacity: 1;
}
#cssmenu ul ul li:hover > ul {
left: 210px;
top: 0;
opacity: 1;
}
#cssmenu.align-right ul ul li:hover > ul {
left: auto;
right: 170px;
top: 0;
opacity: 1;
padding-right: 5px;
}
#cssmenu ul ul li a {
width: 170px;
margin-right: 3px;
border-bottom: 1px solid #eeeeee;
padding: 10px 20px;
font-size: 12px;
color: #559c00;
font-weight:bold;
background: #fff;
-webkit-transition: all .35s ease;
-moz-transition: all .35s ease;
-ms-transition: all .35s ease;
-o-transition: all .35s ease;
transition: all .35s ease;
box-shadow: 3px 3px 8px #818181; /*shadow for CSS3 capable browsers.*/
-webkit-box-shadow: 1px 1px 5px #818181;
-moz-box-shadow: 3px 3px 8px #818181;
}
#cssmenu.align-right ul ul li a {
text-align: right;
}
#cssmenu ul ul li:hover > a {
background: #fff;
color: #72cc00;
}
#cssmenu ul ul li:last-child > a,
#cssmenu ul ul li.last > a {
}
#cssmenu > ul > li > ul::after {
content: '';
border: 6px solid transparent;
width: 0;
height: 0;
border-bottom-color: #559c00;
position: absolute;
top: -12px;
left: 30px;
}
#cssmenu.align-right > ul > li > ul::after {
left: auto;
right: 30px;
}
#cssmenu ul ul li.has-sub::after {
border: 5px solid transparent;
border-left-color: #9ea2a5;
right: 10px;
top: 12px;
-moz-transition: all .2s ease;
-ms-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
-webkit-transition: -webkit-transform 0.2s ease, right 0.2s ease;
}
#cssmenu.align-right ul ul li.has-sub::after {
border-left-color: transparent;
border-right-color: #9ea2a5;
right: auto;
left: 10px;
}
#cssmenu ul ul li.has-sub:hover::after {
border-left-color: #ffffff;
right: -5px;
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
#cssmenu.align-right ul ul li.has-sub:hover::after {
border-right-color: #ffffff;
border-left-color: transparent;
left: -5px;
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
#media all and (max-width: 800px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) {
#cssmenu {
width: auto;
}
#cssmenu.align-center ul {
text-align: left;
}
#cssmenu.align-right > ul > li {
float: none;
}
#cssmenu ul {
width: auto;
}
#cssmenu .submenuArrow,
#cssmenu #indicatorContainer {
display: none;
}
#cssmenu > ul {
height: auto;
display: block;
}
#cssmenu > ul > li {
float: none;
}
#cssmenu li,
#cssmenu > ul > li {
display: none;
}
#cssmenu ul ul,
#cssmenu ul ul ul,
#cssmenu ul > li:hover > ul,
#cssmenu ul ul > li:hover > ul,
#cssmenu.align-right ul ul,
#cssmenu.align-right ul ul ul,
#cssmenu.align-right ul > li:hover > ul,
#cssmenu.align-right ul ul > li:hover > ul {
position: relative;
left: auto;
top: auto;
opacity: 1;
padding-left: 0;
padding-right: 0;
right: auto;
}
#cssmenu ul .has-sub::after {
display: none;
}
#cssmenu ul li a {
padding: 12px 20px;
}
#cssmenu ul ul li a {
border: 0;
background: none;
width: auto;
padding: 8px 35px;
}
#cssmenu.align-right ul ul li a {
text-align: left;
}
#cssmenu ul ul li:hover > a {
background: none;
color: #8c9195;
}
#cssmenu ul ul ul a {
padding: 8px 50px;
}
#cssmenu ul ul ul ul a {
padding: 8px 65px;
}
#cssmenu ul ul ul ul ul a {
padding: 8px 80px;
}
#cssmenu ul ul ul ul ul ul a {
padding: 8px 95px;
}
#cssmenu > ul > #menu-button {
display: block;
cursor: pointer;
}
#cssmenu #menu-button > a {
padding: 14px 20px;
}
#cssmenu ul.open li,
#cssmenu > ul.open > li {
display: block;
}
#cssmenu > ul.open > li#menu-button > a {
color: #fff;
border-bottom: 1px solid rgba(150, 150, 150, 0.1);
}
#cssmenu ul ul::after {
display: none;
}
#cssmenu #menu-button::after {
display: block;
content: '';
position: absolute;
height: 3px;
width: 22px;
border-top: 2px solid #559c00;
border-bottom: 2px solid #559c00;
right: 20px;
top: 15px;
}
#cssmenu #menu-button::before {
display: block;
content: '';
position: absolute;
height: 3px;
width: 22px;
border-top: 2px solid #559c00;
right: 20px;
top: 25px;
}
#cssmenu ul.open #menu-button::after,
#cssmenu ul.open #menu-button::before {
border-color: #fff;
}
}
<code>
I'll be happy if you help me how to fix this issue. Thanks in advance.
You have apply overflow:hidden for the wrapper class. For that reason it is hiding the submenus. Add the following style in your CSS, hopefully it will fix the issue.
header > div.wrapper:first-child
{
overflow:visible !important;
}
NOTE: You can try without !important keyword, if it is not working then apply it like above. Because i am not sure about the order of your CSS written.

CSS drop-down menu in tabs bar disappearing

I'm new to coding and am having some trouble getting a drop-down menu to work.
The menu drops down correctly when my cursor hovers over its corresponding tab, but once I move the cursor down to the actual drop-down sub-categories, they disappear.
Here's the CSS for the tabs:
#cssmenu {
position: relative;
height: 44px;
background: #1d309e;
width: auto;
z-index: 100;
}
#cssmenu ul {
list-style: none;
padding: 0;
margin: 0;
line-height: 1;
}
#cssmenu > ul {
position: relative;
display: block;
background: #1d309e;
height: 32px;
width: 100%;
z-index: 99;
text-transform:lowercase;
}
#cssmenu > ul > li {
display: block;
position: relative;
float: left;
margin: 0;
padding: 0;
font-family: tahoma, "Trebuchet MS", verdana, helvetica, arial, sans-serif;
text-transform:lowercase
z-index: 100
}
#cssmenu > ul > #menu-button {
display: none;
}
#cssmenu ul li a {
display: block;
font-family: tahoma, "Trebuchet MS", verdana, helvetica, arial, sans-serif;
text-decoration: none;
text-transform:lowercase
}
#cssmenu > ul > li > a {
font-size: 15px;
padding: 0px 80px;
color: #ffffff;
-webkit-transition: color 0.25s ease-out;
-moz-transition: color 0.25s ease-out;
-ms-transition: color 0.25s ease-out;
-o-transition: color 0.25s ease-out;
transition: color 0.25s ease-out;
text-transform:lowercase
}
#cssmenu > ul > li.has-sub > a {
padding-right: 32px;
}
#cssmenu > ul > li:hover > a {
color: #fff203;
}
#cssmenu li.has-sub::after {
display: block;
content: '';
position: absolute;
width: 0;
height: 0;
z-index: 100
}
#cssmenu > ul > li.has-sub::after {
right: 10px;
top: 20px;
border: 5px solid transparent;
border-top-color: #ffffff;
}
#cssmenu > ul > li:hover::after {
border-top-color: #fff203;
}
#indicatorContainer {
position: absolute;
height: 12px;
width: 100%;
bottom: 0px;
overflow: hidden;
z-index: 100;
}
#pIndicator {
position: absolute;
height: 0;
width: 100%;
border: 12px solid transparent;
border-top-color: #2b2f3a;
z-index: 100;
-webkit-transition: left .25s ease;
-moz-transition: left .25s ease;
-ms-transition: left .25s ease;
-o-transition: left .25s ease;
transition: left .25s ease;
}
#cIndicator {
position: absolute;
height: 0;
width: 100%;
border: 12px solid transparent;
border-top-color: #2b2f3a;
top: -12px;
right: 100%;
z-index: 100;
}
#cssmenu ul ul {
position: absolute;
left: -9999px;
top: 70px;
opacity: 0;
-webkit-transition: opacity .3s ease, top .25s ease;
-moz-transition: opacity .3s ease, top .25s ease;
-ms-transition: opacity .3s ease, top .25s ease;
-o-transition: opacity .3s ease, top .25s ease;
transition: opacity .3s ease, top .25s ease;
z-index: 100;
}
#cssmenu ul ul ul {
top: 37px;
padding-left: 5px;
}
#cssmenu ul ul li {
position: relative;
z-index: 100
}
#cssmenu > ul > li:hover > ul {
left: auto;
top: 44px;
opacity: 1;
}
#cssmenu ul ul li:hover > ul {
left: 170px;
top: 0;
opacity: 1;
}
#cssmenu ul ul li a {
width: 130px;
border-bottom: 1px solid #eee;
padding: 10px 20px;
font-size: 12px;
color: #1d309e;
background: #fff;
-webkit-transition: all .35s ease;
-moz-transition: all .35s ease;
-ms-transition: all .35s ease;
-o-transition: all .35s ease;
transition: all .35s ease;
}
#cssmenu ul ul li:hover > a {
background: #f6f6f6;
color: #ffee00;
}
#cssmenu ul ul li:last-child > a,
#cssmenu ul ul li.last > a {
border-bottom: 0;
}
.submenuArrow {
border: 6px solid transparent;
width: 0;
height: 0;
border-bottom-color: #fff;
position: absolute;
top: -12px;
}
#cssmenu ul ul li.has-sub::after {
border: 4px solid transparent;
border-left-color: #1d309e;
right: 10px;
top: 12px;
-moz-transition: all .2s ease;
-ms-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
-webkit-transition: -webkit-transform 0.2s ease, right 0.2s ease;
}
#cssmenu ul ul li.has-sub:hover::after {
border-left-color: #fff;
right: -5px;
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
#media all and (max-width: 800px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) {
#cssmenu {
width: auto;
}
#cssmenu ul {
width: auto;
}
#cssmenu .submenuArrow,
#cssmenu #indicatorContainer {
display: none;
}
#cssmenu > ul {
height: auto;
display: block;
}
#cssmenu > ul > li {
float: none;
}
#cssmenu li,
#cssmenu > ul > li {
display: none;
}
#cssmenu ul ul,
#cssmenu ul ul ul,
#cssmenu ul > li:hover > ul,
#cssmenu ul ul > li:hover > ul {
position: relative;
left: auto;
top: auto;
opacity: 1;
padding-left: 0;
z-index: 100
}
#cssmenu ul .has-sub::after {
display: none;
}
#cssmenu ul li a {
padding: 12px 20px;
}
#cssmenu ul ul li a {
border: 0;
background: none;
width: auto;
padding: 8px 35px;
}
#cssmenu ul ul li:hover > a {
background: none;
color: #ffee00;
}
#cssmenu ul ul ul a {
padding: 8px 50px;
}
#cssmenu ul ul ul ul a {
padding: 8px 65px;
}
#cssmenu ul ul ul ul ul a {
padding: 8px 80px;
}
#cssmenu ul ul ul ul ul ul a {
padding: 8px 95px;
}
#cssmenu > ul > #menu-button {
display: block;
cursor: pointer;
}
#cssmenu #menu-button > a {
padding: 14px 20px;
}
#cssmenu ul.open li,
#cssmenu > ul.open > li {
display: block;
}
#cssmenu > ul.open > li#menu-button > a {
color: #fff;
border-bottom: 1px solid rgba(150, 150, 150, 0.1);
}
#cssmenu #menu-button::after {
display: block;
content: '';
position: absolute;
height: 3px;
width: 22px;
border-top: 2px solid #ffffff;
border-bottom: 2px solid #ffffff;
right: 20px;
top: 15px;
z-index: 100
}
#cssmenu #menu-button::before {
display: block;
content: '';
position: absolute;
height: 3px;
width: 22px;
border-top: 2px solid #ffffff;
right: 20px;
top: 25px;
z-index: 100
}
#cssmenu ul.open #menu-button::after,
#cssmenu ul.open #menu-button::before {
border-color: #fff;
}
}
And here is the HTML page I'm trying to put it on:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1' />
<link rel='stylesheet' type='text/css' href='styles.css' />
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'>
</script>
<script type='text/javascript' src='menu_jquery.js'></script>
</head>
<body>
<h1>Sugar Mule</h1>
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'><span>Home</span></a></li>
<li class='has-sub'><a href='about.html'><span>About</span></a>
<ul>
<li><a href='why.html'><span>Why Sugar Mule?</span></a></li>
<li><a href='staff.html'><span>Staff</span></a></li>
<li class='last'><a href='contact.html'><span>Contact</span></a></li>
</ul>
</li>
<li><a href='issues.html'><span>Issues</span></a></li>
<li><a href='books.html'><span>Books</span></a></li>
<li><a href='submit.html'><span>Submit</span></a></li>
<li class='last'><a href='links.html'><span>Links</span></a></li>
</ul>
</div>
<center><img src="logo.png" alt="Logo" width="700" height="450"></center>
</body>
</html>
Thanks in advance for the help!
Because the dropdown #cssmenu > ul > li:hover > ul has a top offset of 44px.
Then you must make sure all the top level links #cssmenu > ul > li > a are atleast 44px
Heres the ammended CSS
#cssmenu > ul > li > a {
...
min-height:44px;
...
}
Fiddle: http://jsfiddle.net/Varinder/bg763/