Can someone please help me? I'm trying to center my navigation menu. I have tried different things, but nothing works, and i really don't know what to do. I would really appreciate help. thanks in advance!
nav {
display: inline-block;
list-style-type: none;
float: left;
width: 100%;
height: 102px;
text-align: center;
}
nav > ul {
float:right;
width:100%;
height:102px;
background:#222;
border-radius: 10px 10px 0px 0px;
}
nav > ul > li {
float:left;
width:auto;
margin-right:10px;
line-height:102px;
}
nav > ul li a {
padding:50px;
color:white;
font-family:helvetica, sans-serif;
}
nav > ul > li > ul {
background:#222;
opacity:0;
transition:opacity 1s;
-webkit-transition:opacity 1s;
-moz-transition:opacity 1s;
-o-transition:opacity 1s;
-ms-transition:opacity 1s;
border-radius: 0px 0px 10px 10px;
}
nav > ul > li:hover > ul {
opacity:1;
}
HTML
<div>
<nav>
<ul>
<li> Hjem
<ul>
<li>Sub1</li>
<li>Sub2</li>
<li>Sub3</li>
</ul>
</li>
<li>Bilder</li>
<li>Video</li>
<li>Design</li>
</ul>
</nav>
</div>
Here is what I did.
#outer{
width:100%;
height: 102px;
text-align: center;
background:#222;
border-radius: 10px 10px 0px 0px;
}
nav {
display: inline-block;
list-style-type: none;
margin: 0 auto;
}
nav > ul > li {
float:left;
width:auto;
margin-right:10px;
line-height:102px;
}
nav > ul li a {
padding:50px;
color:white;
font-family:helvetica, sans-serif;
}
nav > ul > li > ul {
background:#222;
opacity:0;
transition:opacity 1s;
-webkit-transition:opacity 1s;
-moz-transition:opacity 1s;
-o-transition:opacity 1s;
-ms-transition:opacity 1s;
border-radius: 0px 0px 10px 10px;
}
nav > ul > li:hover > ul {
opacity:1;
}
And you just need to give an ID to the div.
<div id="outer">
Related
*
I don't know what I am doing wrong here so can you help me? I want to create a cascading drop-down menu and I can't see what I am doing wrong. I've tried everything. I am just out of ideas
*
HERE IS MY CODE
<style type="text/css">
body {
background:#bf5c71 url('australia1.jpg');
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width:1000px;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
font-family:'Ek Mukta';
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu,
.menu li:hover .sub-menu1{
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu1 {
width:100%;
padding:0px 0px;
position:relative;
top:100%;
left:370px;
z-index:100;
opacity:50;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2758;
}
.sub-menu li,
.sub-menu1 li
{
display:block;
font-size:16px;
}
.sub-menu li a{
padding:10px 30px;
display:block;
}
.sub-menu1 li a{
padding:10px 10px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a,
.sub-menu1 li a:hover, .sub-menu1 .current-item a
{
background:#3e3436;
}
</style>
</body>
</html>
<html>
<head>
<title> Australia </title>
</head>
<body>
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Acasa</li>
<li>Obiective turistice<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Sydney
<ul class="sub-menu1">
<li>Test
</ul>
</li>
<li>Melbourne</li>
<li>Brisbane</li>
<li>Perth</li>
</ul>
</li>
<li class="current-item">Galerie Foto</li>
<li>Video</li>
</ul>
</nav>
</div>
You can use adjacent sibling selector for more info visit this link On a CSS hover event, can I change another div's styling?
Set display:none initially to sub-menu1 class and on hover of sub-menu li a set display of adjacent sub-menu1 back to block.
Here is the code:
body {
background:#bf5c71 url('australia1.jpg');
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width:1000px;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
font-family:'Ek Mukta';
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu,
.menu li:hover .sub-menu1{
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu1 {
width:100%;
padding:0px 0px;
position:relative;
top:100%;
left:370px;
z-index:100;
opacity:50;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2758;
display: none;
}
.sub-menu li,
.sub-menu1 li
{
display:block;
font-size:16px;
}
.sub-menu li a:hover, .sub-menu .current-item a,
.sub-menu1 li a:hover, .sub-menu1 .current-item a
{
background:#3e3436;
display: block;
}
.sub-menu li a:hover + .sub-menu1{
display:block;
padding:10px 10px;
}
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Acasa</li>
<li>Obiective turistice<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Sydney
<ul class="sub-menu1">
<li>Test
</ul>
</li>
<li>Melbourne</li>
<li>Brisbane</li>
<li>Perth</li>
</ul>
</li>
<li class="current-item">Galerie Foto</li>
<li>Video</li>
</ul>
</nav>
</div>
Or you can have an indentation on your submenus? It really depends on what you want. Could you give some example? Here's what I meant when I was talking about indentation :
body {
background:#bf5c71 url('australia1.jpg');
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width:1000px;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
font-family:'Ek Mukta';
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu,
.menu li:hover .sub-menu1{
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu1 {
width:100%;
padding:0px 0px;
position:relative;
top:100%;
left:370px;
z-index:100;
opacity:50;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2758;
}
.sub-menu li,
.sub-menu1 li
{
display:block;
font-size:16px;
}
.sub-menu li a{
padding:10px 30px;
display:block;
}
.sub-menu1 li a{
padding:10px 10px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a,
.sub-menu1 li a:hover, .sub-menu1 .current-item a
{
background:#3e3436;
}
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Acasa</li>
<li>Obiective turistice<span class="arrow">▼</span>
<ul class="sub-menu">
<li>
Sydney
<ul>
<li>Test
</ul>
</li>
<li>Melbourne</li>
<li>Brisbane</li>
<li>Perth</li>
</ul>
</li>
<li class="current-item">Galerie Foto</li>
<li>Video</li>
</ul>
</nav>
</div>
First of all,you must write 0 instead of 0px.
you must make the sub-menu1 display: none; then when mouse is on sydney the sub-menu must be display: block;
i have fixed somethings and this will be your code:
body {
background: #bf5c71;
}
.clearfix:after {
display: block;
clear: both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width: 100%;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
background: #3e3436;
}
.menu {
width: 1000px;
margin: 0 auto;
}
.menu li {
margin: 0;
list-style: none;
font-family: 'Ek Mukta';
}
.menu a {
transition: all linear 0.15s;
color: #919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration: none;
color: #be5b70;
}
.menu .arrow {
font-size: 11px;
line-height: 0;
}
/*----- Top Level -----*/
.menu > ul > li {
float: left;
display: inline-block;
position: relative;
font-size: 19px;
}
.menu > ul > li > a {
padding: 10px 40px;
display: inline-block;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background: #2e2728;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu,
.menu li:hover .sub-menu1 {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 160%;
padding: 5px 0;
position: absolute;
top: 0;
left: 0;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
background: #2e2728;
}
#sydney:hover .sub-menu1 {
display: block;
}
.sub-menu1 {
width: 100%;
padding: 0;
position: relative;
top: 0;
left: 370px;
z-index: 100;
opacity: 50;
transition: opacity linear .15s;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
background: #2e2758;
display: none;
}
.sub-menu li,
.sub-menu1 li {
font-size: 16px;
}
.sub-menu li a {
padding: 10px 30px;
display: block;
}
.sub-menu li a:hover, .sub-menu .current-item a,
.sub-menu1 li a:hover, .sub-menu1 .current-item a {
background: #3e3436;
}
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Acasa</li>
<li>Obiective turistice<span class="arrow">▼</span>
<ul class="sub-menu">
<li id="sydney">Sydney
<ul class="sub-menu1">
<li>Test</li>
</ul>
</li>
<li>Melbourne</li>
<li>Brisbane</li>
<li>Perth</li>
</ul>
</li>
<li class="current-item">Galerie Foto</li>
<li>Video</li>
</ul>
</nav>
</div>
Im making a landing page for a job and doing the navbar then i figured it out that i have to set the navbar fixed to top, after i fixed it the collapse of the second bar is just showing up when im not even hover on it. Had to add more margin to the next item to work "propertly" but is kinda ugly
.fixed-top {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
top: 0;
border-width: 0 0 1px;
}
#nav ul li a {
display: block;
padding: 7px 15px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
}
#nav li a:hover {
color: #000000;
background-color: #fff;
}
#nav .navbar-izquierda ul {
width: 100%;
float: left;
margin: auto;
padding: 0;
list-style: none;
background-color: #434343;
box-shadow: 10px 0 10px #000000;
border-bottom: 1px solid #000000;
}
.clearfix:after {
display:block;
clear:both;
}
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width: auto;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:14px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- DropDown Navbar Inferior -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:100%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition: opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:inline-block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
}
<div class="navbar-izquierda menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li class="active">Portatil</li>
<li>Desk</li>
<li>Workstation</li>
<li>Promotions</li>
<li>Services and Guarantees <span class="arrow">▼</span>
<ul class="sub-menu">
<li>Error 1</li>
<li>Error 2</li>
<li>Horror 3</li>
</ul>
</li>
</ul>
</nav><!-- Navegador inferior -->
</div><!-- Navegador Inferior -->
The key is to set the dropdown to visility:hidden; in the start and visility:visible; in :hover state.
.fixed-top {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
top: 0;
border-width: 0 0 1px;
}
#nav ul li a {
display: block;
padding: 7px 15px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
}
#nav li a:hover {
color: #000000;
background-color: #fff;
}
#nav .navbar-izquierda ul {
width: 100%;
float: left;
margin: auto;
padding: 0;
list-style: none;
background-color: #434343;
box-shadow: 10px 0 10px #000000;
border-bottom: 1px solid #000000;
}
.clearfix:after {
display:block;
clear:both;
}
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width: auto;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:14px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- DropDown Navbar Inferior -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
visibility:visible;
}
.sub-menu {
width:100%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition: opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
visibility:hidden;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:inline-block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
}
<div class="navbar-izquierda menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li class="active">Portatil</li>
<li>Desk</li>
<li>Workstation</li>
<li>Promotions</li>
<li>Services and Guarantees <span class="arrow">▼</span>
<ul class="sub-menu">
<li>Error 1</li>
<li>Error 2</li>
<li>Horror 3</li>
</ul>
</li>
</ul>
</nav><!-- Navegador inferior -->
</div><!-- Navegador Inferior -->
I am having extreme dificulties to add a sub-menu to my dropdown, but I am not a pro on css. I would like to put a submenu on the part it says "10º ano" and "11º ano" in the dropdown "projects", but everything I do doesn't work ! How can I put submenus and open on the right side when cursor is placed ?
---------------------------------------Here is the HTML -------------------------
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Sobre mim</li>
<li>Sobre o curso</li>
<li>
Projectos <span class="arrow">▼</span>
<ul class="sub-menu">
<li>10∘ Ano <span class="arrow">▶ </span> </li>
</li>
<li>11∘ Ano <span class="arrow">▶ </span>
<ul>
</ul>
</li>
</li>
</ul>
</li>
<li>Contactos</li>
</ul>
</nav>
</div>
--------------------------------------------------and here is css ----------------------------------
<style>
<!-- cor rosa #be5b70 -->
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width:1000px;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
font-family:'Ek Mukta';
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#3e3436;
border-radius: 10px;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:130%;
text-align: center;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
border-radius: 10px;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 7px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
border-radius: 10px;
}
.sub-menu li:hover > a, .menu .current-item > a {
text-decoration: none;
color:#E68268;
<!-- lalalalalalal separador-->
li.sub-menu li {
display:none;
position: absolute; left: 100%; top:0;}
li.sub-menu:hover li{
display: block;}
</style>
<!-- cor rosa #be5b70 --> .clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0, 0, 0, 0.2);
background:#3e3436;
}
.menu {
width:1000px;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
font-family:'Ek Mukta';
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0, 0, 0, 0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#3e3436;
border-radius: 10px;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:130%;
text-align: center;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index: -1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0, 0, 0, 0.2);
background:#2e2728;
border-radius: 10px;
}
.sub-menu li {
display:block;
font-size:16px;
position: relative;
}
.sub-menu li a {
padding:10px 7px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
border-radius: 10px;
}
.sub-menu li:hover a, .menu .current-item a {
text-decoration: none;
color:#E68268;
}
/* li.sub-menu li {
display:none;
position: absolute;
left: 100%;
top:0;
}
li.sub-menu:hover li {
display: block;
}*/
.sub-menu li ul {
display: none;
}
.sub-menu li:hover ul {
display: block;
width: 100%;
position: absolute;
left: 100%;
top: 0;
text-align: center;
padding:5px 0px;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0, 0, 0, 0.2);
background:#2e2728;
border-radius: 10px;
}
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Sobre mim</li>
<li>Sobre o curso</li>
<li><a href="#">
Projectos <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li>10∘ Ano <span class="arrow">▶ </span>
<ul>
<li>1Ano </li>
<li>1Ano </li>
</ul>
</li>
<li>11∘ Ano <span class="arrow">▶ </span>
<ul>
<li>1Ano </li>
<li>1Ano </li>
</ul>
</li>
</ul>
</li>
<li>Contactos
</li>
</ul>
</nav>
</div>
For whatever reason, when I add a radio check into the css, it will appear in the menu but will not show any of the menu items. Any tips on getting it to toggle properly would be a huge help!
Here's the fiddle:
http://jsfiddle.net/casslt07/kjjvp1bx/
**HTML**
<div id="nav">
<nav id="nav" class="clearfix">
<!-- nav menu top level -->
<input type="checkbox" id="menu-toggle">
<label for="button" onclick></label>
<ul class="first-level">
<li>Home
<li><a>Posts</a>
<ul>
<li>Listings</li>
<li>Comics</li>
<li>Observations</li>
<li>Poems</li>
<li>Short Stories</li>
</ul>
</li>
<li>Photos
</li>
<li>Videos</li>
<li>About the Author</li>
</ul>
<?php get_search_form(); ?> </nav>
</div>
**CSS:**
/* Config */
body {font-family:Arial}
ul, li {list-style:none; margin:0; padding:0;}
#menu-toggle {
display:none;
}
#nav label {
display:none;
font-size:20px;
list-style:none;
}
/* Nav */
#nav {
background-color:#33447A;
height: inherit;
border-bottom: 3px solid #13EBC7;
position:relative;
display:block; width: 100%; overflow:visible;}
#nav a {
color:#fff; display:block; font-size: 11pt; padding:18px 20px; text-decoration:none; text-align: left;}
#nav ul li {position:relative;}
/* First-Level */
#nav li {transition:background-color .5s; float:left;}
#nav li:hover {background-color:#50AEED; -webkit-transition: margin-bottom .2s; /* Safari 3.1 to 6.0 */
transition: margin-bottom .2s;}
#nav > ul > li {display:block; float:left; }
/* Second-level */
#nav li ul {width: 100%;}
#nav > ul li:hover > ul {opacity:1; top:54px; visibility:visible; border-radius: 4px; z-index:3; }
#nav .first-level .second-level > li {float:left;}
#nav > ul ul {opacity:0; visibility:hidden; position:absolute; top:60px; transition:all .25s; width:1000px;}
#nav > ul ul li {background-color:#3498db; left:0;}
#nav > ul ul li a {padding:10px 20px}
/* Clearfix */
.clearfix:after {visibility: hidden; display: block; font-size: 0; content:" "; clear:both; height:0;}
.nav-search {
opacity: .25;
width:35%;
float: right;
display:inline;
position: relative;
background: #3498db;
background: url('http://1touchsigns.com/images/search.gif');
background-repeat: no-repeat;
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
border:none;
top:7px;
padding:6px;
outline:none;
transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
}
.nav-search:focus {
background: white;
opacity: 1;
}
#responsive {
display: none;
}
#media only screen and (max-width: 480px) {
#menu-toggle {
display:block;
}
#nav label {display: block;height:50px;width:50px;line-height:50px;text-align:center;color:white;font-size:150%;background-color: #83CE69; cursor:pointer;}
#menu-toggle:checked + #nav {display: block;}
#nav label:active #nav {display: none;}
#nav {
display: block;
width: 100%;
height:auto;
float: right;
margin-right: 10px;
background-color: #232323;
border-bottom-width: 0px;
}
#nav ul {
display:none;
}
#nav ul:hover {
display:block;
}
#nav li {
width:100%;
}
#nav ul ul li {
width:100%;
color:white;
background-color:black;
display:block;
}
#nav ul ul li:hover {
display:block;
}
}
Add
#menu-toggle:checked + label + ul {
display: block;
}
http://jsfiddle.net/kjjvp1bx/3/
Or use jQuery, both works:
http://jsfiddle.net/kjjvp1bx/2/
Whenever I hover my mouse under the buttons that have drop down menus, the drop down menu shows. I want to make it so the drop down menu only shows when I put my mouse over the actual button.
FIDDLE CODE
HTML
<div id="navbar">
<ul>
<li>Home</li>
<li>Cakes
<ul>
<li >Budget Cakes</li>
<li>Wedding</li>
<li >Cakes to Go</li>
<li >Cake Bonbons</li>
<li >Holiday Cakes</li>
<li >Cakes for Girls</li>
<li >Cakes for Boys</li>
<li >For Her</li>
<li >For Him</li>
<li >Cupcakes</li>
</ul>
</li>
<li>Classes</li>
<li>Flavors</li>
<li>Events
<ul>
<li>Beach Wedding</li>
<li>Baby Showers</li>
<li>Sweet 15-16</li>
</ul>
</li>
<li>Contact</li>
<li>Questions</li>
</ul>
</div><!--end of navbar-->
CSS
#navbar ul li:hover > ul {
height:auto !important;
opacity:1;
}
#navbar ul li:hover > ul > li {
height:50px !important;
opacity:1;
}
#navbar ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: webkit-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
padding: 0 40px;
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
list-style:none;
position:relative;
display:inline-table;
}
#navbar ul:after {
content:"";
clear: both;
display: block;
}
#navbar ul li {
float:left;
-webkit-transition:background 0.3s ease-in;
-moz-transition:background 0.3s ease-in;
-o-transition:background 0.3s ease-in;
-ms-transition:background 0.3s ease-in;
transition:background 0.3s ease-in;
position:relative;
}
#navbar ul li:hover {
background:#4b545f;
}
#navbar ul li:hover a {
color:#fff;
}
#navbar ul li a {
display:block;
padding:25px 40px;
color:#757575;
text-decoration:none;
}
#navbar ul ul {
background: #5f6975;
border-radius:0px;
-webkit-border-radius:0px;
-moz-border-radius:0px;
padding: 0;
position:absolute;
top:100%;
left:0px;
width:195px;
z-index:1;
-webkit-transition:all 0.4s ease-in-out;
transition:all 0.4s ease-in-out;
opacity:0;
height:0px;
}
#navbar ul ul li {
float:none;
border-top:1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position:relative;
height:0px;
-webkit-transition:all 0.4s ease-in-out;
transition:all 0.4s ease-in-out;
opacity:0;
}
#navbar ul ul li a {
padding: 15px 40px;
color:#fff;
}
#navbar ul ul li a:hover {
background: #4b545f;
}
#navbar {
text-align:center;
}
#navbar ul ul ul {
position:absolute;
left:100%;
top:0;
width:155px;
}
It's because your nested <ul> still has a height, and so when you hover on it, the browser considers that as hovering on part of the first <li>.
Easiest way to fix it is to set the subnav ul to display: block and overflow: hidden.
#navbar ul ul {
...(existing styles)
display: block;
overflow: hidden;
}
Demo
Alternatively, you can toggle visibility: hidden.
#navbar ul ul {
...(existing styles)
visibility: hidden; /* ADD */
}
#navbar ul li:hover > ul {
...(existing styles)
visibility: visible; /* ADD */
}
Demo 2
Add following CSS.
#navbar ul ul {
display: block;
overflow: hidden;
}