The submenu doesn't show up when hover the mouse - html

I have a problem. I don't know what wrong with the code as when I hover the mouse over 'About us', the submenu didn't show up. I did make the submenu display:none and then when hover, it display: block but nothing happen. Thanks for your help
#nav_menu{
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#nav_menu li{
float: left;
}
#nav_menu li a{
display: block;
width: 160px;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
text-align: center;
}
#nav_menu .current{
color: yellow;
}
#nav_menu #sub_menu{
display: none;
position: absolute;
top: 100%;
list-style: none;
}
#nav_menu #sub_menu:hover{
display: block;
}
#nav_menu #sub_menu li a{
float: right;
}
<ul id="nav_menu">
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Tickets</li>
<li>About Us
<ul id="sub_menu">
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>

My method is a little different and shorter with the animation opening and closing for the submenu, I used the scale instead of display for animation;
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#nav_menu{
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#nav_menu li{
float: left;
position: relative;
}
#nav_menu li a{
display: block;
width: 160px;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
text-align: center;
}
#nav_menu .current{
color: yellow;
}
#nav_menu #sub_menu{
position: absolute;
top: 100%;
list-style: none;
padding: 0;
transform : scaleY(0);
transform-origin: top;
transition: all 0.4s;
}
#nav_menu li:hover #sub_menu{
transform: scaleY(1);
}
#nav_menu #sub_menu li a{
float: right;
}
<ul id="nav_menu">
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Tickets</li>
<li>About Us
<ul id="sub_menu">
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>

To display a submenu when hovering, you need to write like this:
#nav_menu li:hover #sub_menu {
display: block;
}
Because you are accessing the #sub_menu selector. Also, you need to add position: relative the selector #nav_menu li is relevant for the correctness of your position: absolute of the selector #nav_menu #sub_menu. And add padding: 0 for the selector of the same selector #nav_menu #sub_menu, in order to align it under the main menu.
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#nav_menu{
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#nav_menu li{
float: left;
position: relative;
}
#nav_menu li a{
display: block;
width: 160px;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
text-align: center;
}
#nav_menu .current{
color: yellow;
}
#nav_menu #sub_menu{
display: none;
position: absolute;
top: 100%;
list-style: none;
padding: 0;
}
/*#nav_menu #sub_menu:hover{
display: block;
}*/
#nav_menu li:hover #sub_menu{
display: block;
}
#nav_menu #sub_menu li a{
float: right;
}
<ul id="nav_menu">
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Tickets</li>
<li>About Us
<ul id="sub_menu">
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>

Related

aligning sub menu with the main menu

My sub-menu and sub-sub-menu seem to have a lot of gap from each other and is not aligned with the main menu. I want the sub-menu to drop down straight from the main menu and sub-sub-menu to open up on the right side of the sub-menu when hovered over. How can I do that?
below are my codes:
.nav-bar {
max-height: 0;
margin-left: 0;
padding-left:20px;
padding-top: 200px;
}
.box-nav-bar ul{
display:inline-block;
text-decoration: none;
padding: 0;
list-style-type: none;
margin:0;
}
.box-nav-bar ul li{
display: inline-block;
padding: 20px;
border: 1px solid grey;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
position: relative;
}
.box-nav-bar ul li a{
text-decoration: none;
list-style: none;
color: black;
font-size: 18px;
font-weight: bold;
font-family: Arial;
display:block;
}
.box-nav-bar ul li:hover{
background-color: grey;
}
.box-nav-bar ul .sub-menu ul li{
text-decoration: none;
padding: 0;
margin: 0;
list-style-type: none;
width: 150px;
}
.box-nav-bar ul .sub-menu {
display: none;
font-size: 14px solid;
position:absolute;
text-align: center;
}
.box-nav-bar li:hover .sub-menu{
display: block;
}
.sub-sub-menu{
display: none;
font-size: 14px solid;
position:absolute;
text-align: center;
}
.box-nav-bar li:hover .sub-menu li:hover{
display: block;
}
<div class="nav-bar">
<nav class="box-nav-bar">
<ul>
<li> HOME</li>
<li> ABOUT</li>
<li> SERVICES
<ul class="sub-menu">
<li>
Lorem ipsum
</li>
<li>
Dolor sit amet
</li>
<li>
Conse ctetur
<ul class="sub-sub-menu">
<li>
Latest
</li>
<li>
Archive
</li>
</ul>
</li>
</ul>
</li>
<li> PROJECTS</li>
<li> CONTACTS</li>
</ul>
</nav>
</div>
Thank you.
You have position: absolute on your .sub-menu and .sub-sub-menu. You just have to align your container blocks using the top and left properties.
Also font-size: 14px solid is invalid as solid is a border-type attribute and not required with font-size. Change it simply to font-size: 14px.
Refer code:
.nav-bar {
max-height: 0;
margin-left: 0;
padding-left: 20px;
padding-top: 200px;
}
.box-nav-bar ul {
display: inline-block;
text-decoration: none;
padding: 0;
list-style-type: none;
margin: 0;
}
.box-nav-bar ul li {
display: inline-block;
padding: 20px;
border: 1px solid grey;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
position: relative;
}
.box-nav-bar ul li a {
text-decoration: none;
list-style: none;
color: black;
font-size: 18px;
font-weight: bold;
font-family: Arial;
display: block;
}
.box-nav-bar ul li:hover {
background-color: grey;
}
.box-nav-bar ul .sub-menu ul li {
text-decoration: none;
padding: 0;
margin: 0;
list-style-type: none;
width: 150px;
}
.box-nav-bar ul .sub-menu {
display: none;
font-size: 14px;
position: absolute;
text-align: center;
top: 91px;
left: 0;
}
.box-nav-bar li:hover .sub-menu {
display: block;
}
.sub-sub-menu {
display: none;
font-size: 14px;
position: absolute;
text-align: center;
top: 0px;
left: 140px;
}
.box-nav-bar li:hover .sub-menu li:hover {
display: block;
}
<div class="nav-bar">
<nav class="box-nav-bar">
<ul>
<li> HOME</li>
<li> ABOUT</li>
<li> SERVICES
<ul class="sub-menu">
<li>
Lorem
</li>
<li>
Dolor
</li>
<li>
Conse
<ul class="sub-sub-menu">
<li>
Latest
</li>
<li>
Archive
</li>
</ul>
</li>
</ul>
</li>
<li> PROJECTS</li>
<li> CONTACTS</li>
</ul>
</nav>
</div>
This will help you get started.
.nav-bar {
max-height: 0;
margin-left: 0;
padding-left: 20px;
padding-top: 200px;
}
.box-nav-bar ul {
display: inline-block;
text-decoration: none;
padding: 0;
list-style-type: none;
margin: 0;
}
.box-nav-bar ul li {
display: inline-block;
padding: 20px;
border: 1px solid grey;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
position: relative;
}
.box-nav-bar ul li a {
text-decoration: none;
list-style: none;
color: black;
font-size: 18px;
font-weight: bold;
font-family: Arial;
display: block;
}
.box-nav-bar ul li:hover {
background-color: grey;
}
.box-nav-bar ul .sub-menu ul li {
text-decoration: none;
padding: 0;
margin: 0;
list-style-type: none;
width: 150px;
}
.box-nav-bar ul .sub-menu {
display: none;
font-size: 14px solid;
position: absolute;
text-align: center;
left: 0;
top: 100%;
}
.box-nav-bar li:hover .sub-menu {
display: block;
}
.sub-menu li {
width: 100% !Important;
}
.sub-menu li:hover .sub-sub-menu {
display: block !important;
}
.sub-sub-menu {
display: none !important;
font-size: 14px solid;
position: absolute;
text-align: center;
top: -2px;
left: 100%;
}
.box-nav-bar li:hover .sub-menu li:hover {
display: block;
}
.sub-sub-menu li {
width: 100% !important;
display: block !important;
padding: 20px !important;
}
<div class="nav-bar">
<nav class="box-nav-bar">
<ul>
<li> HOME</li>
<li> ABOUT</li>
<li> SERVICES
<ul class="sub-menu">
<li>
Lorem ipsum
</li>
<li>
Dolor sit amet
</li>
<li>
Conse ctetur
<ul class="sub-sub-menu">
<li>
Latest
</li>
<li>
Archive
</li>
</ul>
</li>
</ul>
</li>
<li> PROJECTS</li>
<li> CONTACTS</li>
</ul>
</nav>
</div>

Dropdown menu floating left

I made a menu, and I want the dropdown to go centered underneath the 'Fruitsoorten' tab. But now all three of the items are next to each other.
Does anyone know how to fix this? Thanks in advance.
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
margin-top: 55px;
background-color: black;
}
nav li {
display: inline-block;
position: relative;
padding: 10px;
}
nav li ul {
display: none;
}
nav li li {
display:
}
nav li:hover ul {
display: block;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
}
nav li:hover {
background-color: gray;
}
<nav>
<ul>
<li>Home</li>
<li>
Fruitsoorten
<ul>
<li>Kersen</li>
<li>Appels</li>
<li>Pruimen</li>
</ul>
<li>
<li>Team</li>
<li>Agenda</li>
<li>Foto's</li>
<li>Vacatures</li>
<li>Contact</li>
</ul>
</nav>
You can also try this styles.
http://codepen.io/nehemc/pen/LkyQvq
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
margin-top: 55px;
background-color: black;
}
nav li {
display: inline-block;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
padding: 10px;
display:block;
}
nav ul ul {
display: none;
position: absolute;
z-index: 999;
left: 0;
margin-top: 0;
}
nav li:hover ul {
display: block;
}
nav li:hover {
background-color: gray;
}
Add following code to reflect
nav ul { margin-top: 0; }
nav li ul {
display: none;
position: absolute;
left: 0;
z-index: 9;
}
Also clear your HTML code with proper closing of </li>
To affect your inline-block styling to main ul only,
Do this:
nav>ul>li {
display: inline-block;
position: relative;
padding: 10px;
}
instead of
nav li { display: inline-block; position: relative; padding: 10px; }
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
margin-top: 55px;
background-color: black;
}
nav>ul>li {
display: inline-block;
position: relative;
padding: 10px;
}
nav li ul {
display: none;
}
nav li li {
display:
}
nav li:hover ul {
display: block;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
}
nav li:hover {
background-color: gray;
}
<nav>
<ul>
<li>Home
</li>
<li>Fruitsoorten
<ul>
<li>Kersen
</li>
<li>Appels
</li>
<li>Pruimen
</li>
</ul>
</li>
<li>Team
</li>
<li>Agenda
</li>
<li>Foto's
</li>
<li>Vacatures
</li>
<li>Contact
</li>
</ul>
</nav>
is that what you want?
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
background-color: black;
}
nav li {
display: inline-block;
position: relative;
padding: 10px;
}
nav li ul {
display: none;
}
nav li li {
display:
}
nav li:hover ul {
display: block;
position: absolute;
left: 0;
padding:0;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
}
nav li:hover {
background-color: gray;
}
ul.inner li{width:83%}
<nav>
<ul>
<li>Home</li>
<li>Fruitsoorten
<ul class="inner">
<li>Kersen</li>
<li>Appels</li>
<li>Pruimen</li>
</ul>
<li>
<li>Team</li>
<li>Agenda
<li>Foto's</li>
<li>Vacatures</li>
<li>Contact</li>
</ul>
</nav>

Sub menus is not properly displayed

I have a top menu aside in the main menu. This top menu have submenus, but this submenu doesn't behave properly. I can hover only the first submenu, the rest are not. How to fix this?
Here is my code:
.top-menuv2 ul {
list-style-type: none;
margin: 10px 20px 0 700px;
font-size: 0.80em;
float: none;
}
.top-menuv2 ul li {
display: inline;
margin-right: 20px;
font-family: 'Open Sans Bold', sans-serif;
line-height: 1.8;
}
.top-menuv2 a {
color: black;
}
.top-menuv2 .top-navigation {
text-align: center;
}
.top-menuv2 ul li>a:hover {
color: #555;
text-decoration: underline;
}
.top-menuv2 li:hover>ul {
display: block;
}
.top-menuv2 ul li>a:active {
color: #d31716;
}
.top-menuv2 li {
display: inline-block;
position: relative;
}
.top-menuv2 li>ul {
position: absolute;
right: -50%;
top: 20%;
width: auto;
display: none;
white-space: nowrap;
}
.top-menuv2>li>ul {
top: auto;
right: -50%;
width: 100%;
}
.top-menuv2 li>a:after {
margin-left: 5px;
content: '\f107';
font-family: FontAwesome;
}
.top-menuv2>li>a:after {
margin-left: 5px;
content: '\f107';
font-family: FontAwesome;
}
.top-menuv2 li>a:only-child:after {
margin-left: 0;
content: '';
}
.top-menuv2 li>ul>li {
display: block;
}
<div class="top-navigation top-menuv2">
<ul>
<li class="cs cc"> Customer Service 02 753 57 11</li>
<li>Contacts</li>
<li>Our Partners
<ul>
<li>Tangible benefits for retailers</li>
<li>Retailer Registration Process</li>
</ul>
</li>
<li>Careers
<ul>
<li>A Career with Home Credit</li>
<li>Recruitment Process</li>
<li>Vacancies</li>
<li>Corporate Culture</li>
</ul>
</li>
</ul>
</div>
You have to change the z-index of .top-menuv2 li > ul. Add z-index: 99; to your .top-menuv2 li > ul. Because by default #site-navigation .menu > ul > li go over top menu li.

HTML submenu won't work

I am trying to make a website with a dropdown menu. After reading several guides and even searching here, The menu keeps doing weird stuff. I tried a lot of things so some lines may become superfluous.
The submenu is not underneath the menu but next to it.
Someone that can help me?
thx in advance
html:
<div id="menu">
<ul>
<li class="current_page_item">Home</li>
<li>Hardware
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul></li>
<li>About Us</li>
<li>sjabloon</li>
<li>Contact Us
</li>
</ul>
</div> <!-- menu -->
Css:
#menu
{
position: absolute;
right: 0;
}
#menu ul
{
display: inline-block;
line-height: 1em;
position: relative; /* naast elkaar*/
right: 0;
top: 2em;
list-style: none;
/*display: inline-table;*/
}
/*
#menu ul: after
{
content: "";
clear: both;
display: inline-block;
}*/
#Menu ul ul {
display: none;
}
/*
#Menu ul li:hover > ul
{
display: inline-block;
}
*/
#menu ul li
{
float: left; /* op een lijn */
margin-left: 0.50em;
padding: 1em 1.5em;
letter-spacing: 0.20em;
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
color: #OOC;
outline: 0;
}
#menu ul li:hover {
background: #00F;
}
#menu ul li:hover a {
color: #FFF;
}
#menu ul li a /*#menu ul li span*/
{
display: inline-block
margin-left: 0.50em;
letter-spacing: 0.20em;
text-decoration: none; /* geen onderlijning*/
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
outline: 0;
color: #OOC;
}
#menu ul ul /* submenu*/
{
background: #00F;
top: 100%;
padding: 0;
position: absolute;
visibility: hidden;
}
#menu ul:hover ul
{
visibility:visible;
}
#menu ul ul li
{
float: none; /*onder mekaar */
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
position: relative;
color: #FFF;
}
This will help you:
HTML
<div id="menu">
<ul>
<li class="current_page_item">Home
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>Hardware
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>About Us
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>sjabloon
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
</ul>
</div>
StyleSheet
#menu {
position: absolute;
right: 0;
}
#menu ul {
display: inline-block;
line-height: 1em;
position: relative;
/*right: 0;*/
top: 2em;
list-style: none;
}
#menu ul li {
float: left;
padding: 1em 1.5em;
letter-spacing: 0.20em;
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
color: #00C;
outline: 0;
}
#menu ul li a {
display: inline-block;
margin-left: 0.50em;
letter-spacing: 0.20em;
text-decoration: none;
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
outline: 0;
color: #00c;
}
#menu ul li:hover {
background: #00F;
}
#menu ul li:hover a {
color: #FFF;
}
#menu ul:hover ul {
visibility: visible;
}
#menu ul ul {
/*display: none;*/
background: #00F;
top: 100%;
padding: 0;
position: absolute;
visibility: hidden;
}
#menu ul ul li {
float: none;
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
position: relative;
color: #FFF;
}
Here is the Demo
This is certainly not complete, but it should give you a good start. The main thing I would suggest is focusing on your ul li groupings: JS Fiddle
HTML
<div id="menu">
<ul>
<li class="current_page_item">Home
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>Hardware
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>About Us
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>sjabloon
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
</ul>
</div>
CSS
#menu {
position: absolute;
right: 0;
}
#menu ul {
display: inline-block;
line-height: 1em;
position: relative;
/* naast elkaar*/
right: 0;
list-style: none;
/*display: inline-table;*/
}
/*
#menu ul: after
{
content: "";
clear: both;
display: inline-block;
}*/
#Menu ul li ul {
height: 0;
}
#Menu ul li:hover > ul {
height: 10px;
}
#menu ul li {
/* op een lijn */
padding: 1em;
letter-spacing: 0.20em;
font-size: 0.90em;
text-transform: uppercase;
color: #OOC;
outline: 0;
}
#menu ul li:hover {
background: #00F;
}
#menu ul li:hover a {
color: #FFF;
}
#menu ul li a
/*#menu ul li span*/
{
letter-spacing: 0.20em;
text-decoration: none;
/* geen onderlijning*/
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
outline: 0;
color: #OOC;
}
#menu ul li ul
/* submenu*/
{
width: 86px;
background: #00F;
height: 0;
overflow: hidden;
text-align: center;
display: block;
-webkit-transition: all .8s ease;
-moz-transition: all .8s ease;
-ms-transition: all .8s ease;
-o-transition: all .8s ease;
transition: all .8s ease;
position: absolute;
}
#menu ul:hover > li ul {
height: 90px;
width: 86px;
padding: 20px;
}
#menu ul li ul li {
/*onder mekaar */
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
color: #FFF;
}

dropdown menu: whole menu comes down

I'm trying to make a basic dropdown menu with css and html. However when I hover on the li that has to drop down, my whole menu comes down with it.
This is my code:
<nav class="icons">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
<li>Account
<ul id="login">
<li>Change password</li>
<li>Update details</li>
<li>Logout</li>
</ul>
</li>
</ul>
</nav>
And the CSS
nav {
height: 70px;
width: 100%;
position: fixed;
top: 0;
left: 0;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
ul {
margin: 0;
padding: 0;
list-style: none;
margin-left: 5%;
}
ul li {
display: inline-block;
width: 15%;
text-align: center;
line-height: 70px;
}
ul li a {
text-decoration: none;
color: #fff;
font-size: 2em;
display: block;
}
ul li a:hover {
border-bottom: solid black 1px;
}
ul#login{
margin: 0;
padding: 0;
list-style: none;
}
ul#login li {
display: block;
width: 30%;
text-align: center;
line-height: 70px;
}
ul#login li a {
text-decoration: none;
color: #fff;
font-size: 2em;
display: block;
}
ul#login li ul li{
width: 20%;
}
ul#login li ul li a {
text-decoration: none;
color: #fff;
font-size: 0.7em;
display: block;
}
ul#login li a:hover {
border-bottom: solid black 1px;
}
I know it's a lot of CSS for such a basic menu but I don't know how to make it more compact.
Can someone please tell me what I'm doing wrong with the dropdown menu?
Add this css
ul li{
position:relative;
}
#login{
position:absolute;
top:71px;
left:0;
}
FIDDLE