HTML/CSS drop down menu (hover) - html

hi I am having trouble with my dropdown menu.
Here is the HTML code
<div class="sticky-nav">
<a id="mobile-nav" class="menu-nav" href="#menu-nav"></a>
<div id="logo">
<a id="goUp" href="index.html" title="CyberSprint"></a>
</div>
<nav id="menu">
<ul id="menu-nav">
<li>About Us</li>
<li>Solutions
<ul id="submenu-nav">
<li> Healthcare ITSolutions</li>
<li>Government IT Solutions</li>
</ul>
</li>
<li>Services
<ul id="submenu-nav">
<li>Risk Management</li>
<li>Audit & Assessment</li>
<li>Disaster Recovery & Business Continuity Planning</li>
</ul>
</li>
<li>Contact</li>
<li> Login</li>
</ul>
</nav>
</div>
and here is the CSS code
nav#menu {
float: left;
margin-left: 50px;
margin-top: 10px;
}
nav#menu #menu-nav {
margin: 0;
padding: 0;
}
nav#menu #menu-nav li {
list-style: none;
display: inline-block;
margin-left: 50px;
}
nav#menu #menu-nav li:first-child {
margin-left: 0;
}
nav#menu #menu-nav li a {
color: #FFFFFF;
font-size: 16px;
font-weight: 300;
line-height: 60px;
display: block;
text-transform: uppercase;
}
nav#menu #menu-nav li.current a,
nav#menu #menu-nav li a:hover {
color: #23aae1;
}
nav#menu #menu-nav li ul li {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
nav#menu #menu-nav li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
nav#menu #menu-nav li ul li {
background: #666;
}
Thank you

What is the problem that you are having?
You Shouldn't put identical ids in one document.
The sub-menus shouldn't be visible:
ul > li > ul {
display: none;
}
Maybe this is what you are looking for?
ul > li:hover > ul {
display: block;
}
This is a working example:
http://codepen.io/anon/pen/gpJrov

Again, you did not mention what the actual problem was here, but here are a few things I see wrong here...
1: even though you are not calling the ID's in your CSS, your HTML shows multiple elements with the same ID...you shouldn't do that.
2: you have
nav#menu #menu-nav li ul li { ... }
listed 3 times here.
- just add the third one with the first one...
- the second one is where you are having some of your problems.
for the your
nav#menu #menu-nav li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
block, you need to add :hover after the first li, else this isn't doing anything for you...
3: in your first
nav#menu #menu-nav li ul li { ... }
block, get rid of
visibility:hidden
and
opacity:0
they are not needed here...
after making these changes, I got your code to run just fine; though you will need to adjust the positioning of your nested lists...they are all the way to the left...
hope this helps.

Related

I need help in fixing my drop down menu from moving when showing <li>

The Problem:
Look at Offers and the li:
After putting position: absolute
Current vs What I want to achieve
How to make my drop down menu so that when I hover on "Offers" the text doesn't move to the left? I would also like to decrease the width of the li as it is too big for me.
I have tried changing the display: property and putting spaces before and after the word "Offers" in HTML. The spaces worked but I didnt like it because the Offers will just look like having more space than the other options.
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul li ul li {
display: none; /*So li dont show up unless hover */
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
I want to dropdown menu to not move when the li is shown in the Offers. And I would like to decrease the width of black background of the li
That's because the sub menu is taking a place and make its parent li wider.
A possible solution is to set the ul child position: absolute so it will not take a place.
Like this:
.menu ul ul {
position: absolute;
}
Live example:
body {
background: url(https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg) 0 0;
background-size: cover;
}
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
position: relative;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul ul {
position: absolute;
width: 100%;
}
.menu ul li ul li {
display: none;
/*So li dont show up unless hover */
}
.menu ul li ul li a {
padding: 0;
text-align: center;
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
The problem lies with the min-content size of the list items in the drop down, which are larger than the size of the parent list items in the top menu.
e.g. 'packages' renders at 120px whereas 'offers' is 98px.
The simplest solution is to set a max-width for all the list items based on the max-content size of the longest word (not very dynamic though).
Otherwise, use position:absolute to layout the sub menu as in this example:
https://codepen.io/skippingredpanda/pen/xNrxVg
Is simple, use:
.menu li { position: relative; } .menu li ul { position: absolute; top: your horizontal nav height; left: 0;}
And also you have a mistake in code, must be like this:
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>
Link 3
<ul>
<li>SubLink 1</li>
<li>SubLink 2</li>
<li>SubLink 3</li>
<li>SubLink 4</li>
</ul>
</li>
<li>Link 4</li>
</ul>
ul li {position: relative;}
ul li ul {position: absolute; display: none;}
ul li:hover ul {display: block;}

Css dropdown navbar issue

I am making a css navbar dropdown, and am having some issues. I'm not the most experienced person in css, so a little help would be appreciated.
The products text doesn't change color, like on the other ones and you can only click on the text of the products box.
Also the dropdown is not horizontally aligned with the products box.
Here's a link to jsfiddle:
https://jsfiddle.net/epp0zmd6/
Code(HTML):
<div class="navbar">
<ul>
<li class="active">Homepage</li>
<li>Contact Us</li>
<li>Web Learning Platform</li>
<li><a href="#">Products
<ul>
<li>Requirement Extraction & Analysis</li>
<li>Early Deduction Modelling & Analysis</li>
</ul>
</li></a>
</ul>
</div>
Code(CSS):
.navbar ul {
display: inline-table;
vertical-align: middle;
list-style: none;
position: relative;
}
.navbar ul:after {
content: "";
clear: both;
display: block;
}
.navbar ul ul {
display: none;
border-radius: 0;
padding: 0;
position: absolute;
top: 100%;
}
.navbar ul ul li {
float: none;
position: relative;
}
.navbar ul li:hover > ul {
display: block;
}
.navbar ul li {
background-color: #0A6CA3;
display: inline-block;
vertical-align: middle;
font-family: SinkinSans;
font-size: 20px;
padding-top: 27px;
padding-bottom: 21px;
padding-left: 10px;
padding-right: 10px;
color: #FFFFFF;
transition: all 0.8s;
-moz-transition: all 0.8s;
-webkit-transition: all 0.8s;
-o-transition: all 0.8s;
margin-left: -2px;
margin-right: -2px;
float: left;
}
.navbar ul li:hover {
background-color: #FFFFFF;
color: #00A3FF;
}
.navbar ul a {
text-decoration: none;
}
.navbar ul a:visited {
color: #FFFFFF;
}
.navbar ul a:hover {
color: #00A3FF;
}
.navbar ul .active {
background-color: #FFFFFF;
color: #00A3FF;
}
the first mistake is, always put anchor tag inside the li tag
and second mistake is for the dropdown use ul > li > a and than, start child ul before closing li and after closing the anchor tag
and for proper clicking i have put padding on anchor tag with display inline block property.
i have updated fiddle i think you want something like this try this, hope the code will help you.
.navbar ul {
display: inline-table;
vertical-align: middle;
list-style: none;
position: relative;
}
.navbar ul:after {
content: "";
clear: both;
display: block;
}
.navbar ul ul {
display: none;
border-radius: 0;
padding: 0;
position: absolute;
top: 100%;
}
.navbar ul li:hover > ul {
display: block;
}
.navbar ul li {
display: inline-block;
margin-left: -2px;
margin-right: -2px;
float: left;
}
.navbar ul li >a{
padding-top: 27px;
padding-bottom: 21px;
padding-left: 10px;
padding-right: 10px;
display:inline-block;
color:#fff;
text-decoration: none;
background-color: #0A6CA3;vertical-align: middle;
font-family: SinkinSans;
font-size: 20px;
transition: all 0.8s;
-moz-transition: all 0.8s;
-webkit-transition: all 0.8s;
-o-transition: all 0.8s;
}
.navbar ul li:hover >a,
.navbar ul li.active >a{
background-color: #FFFFFF;
text-decoration: none;
color: #00A3FF;
}
<div class="navbar">
<ul>
<li class="active">Homepage</li>
<li>Contact Us</li>
<li>Web Learning Platform</li>
<li>Products
<ul>
<li>Requirement Extraction & Analysis</li>
<li>Early Deduction Modelling & Analysis</li>
</ul>
</li>
</ul>
</div>
You have 2 links on your "Products" entry, that's too much:
<li><a href="#">Products
etc.
Just remove one.
Concerning the position of the dropdown: add
.navbar ul li { left: -8px; }

Submenu keep hiding on moving mouse from menu to submenu

Whenever I move my mouse to submenu, the list disappears suddenly.
I tried using z-index also, but it's not working. Most probably there is some other element overlapping my navigation menu.
here is Code Snippet for menu part:-
.nav {
background: url(images/bgnav.jpg);
clear: both;
height: 40px;
font-size:11px;
text-shadow:0 1px 1px #fff;
line-height: 40px;
}
.nav li {
float: left;
list-style-type: none;
text-transform:uppercase;
}
.nav li a {
color: #676767;
text-decoration: none;
padding:10px 8px;
}
.nav li:hover {
color: #fff;
text-decoration: none;
background:url(images/nav-hover.png);
text-shadow:0 1px 1px #000;
}
.nav li ul {
display: none;
height: auto;
margin: 0;
padding: 0;
}
.nav li:hover ul {
display: block;
position: absolute;
transition-delay: 0s;
}
.nav li ul li {
background: url(images/bgnav.jpg);
}
.nav li ul li a:hover {
background:url(images/nav-hover.png);
}
.submenu li{
transition: 0.2s 1s;
text-shadow:0 1px 1px #fff;
}
<div class="nav">
<div class="mainbody"><!-- #BeginLibraryItem "/Library/nav.lbi" --><ul>
<li>Home </li>
<li>About us</li>
<li>Company Profile</li>
<li>Babbitt Bearing Manufacturing</li>
<li>Rebabbitt Bearing
<ul class="submenu">
<li>White Bearing</li>
</ul>
</li>
<li> Quality</li>
<li> Reverse Engineering</li>
<li> in Situ Services</li>
<li> Contact us </li>
</ul><!-- #EndLibraryItem --></div>
</div>
Can anybody tell me what should I do to solve my problem?
Thank You
Try following css it's overlapping with your absshadow block apply z-index along with position property
This will solve your issue
.nav li {
float: left;
list-style-type: none;
text-transform: uppercase;
/* padding-bottom: 10px; */
z-index: 999;
position: relative;
}
I hope this will solve your problem

CSS/HTML Drop Menu going away after moving mouse

I have a menu and some of my links have dropdown menus. Hovering over the link brings down the dropdown menu, but if I move my cursor onto the actual dropdown menu, the dropdown menu disappears.
Please help!
Here is the CSS and HTML of the actual menu:
CSS:
.menu ul {
color: #3d3d3d;
text-align: right;
float: right;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
.menu ul li {
font-family: LemonMilk;
font-size: 24px;
font-weight: bold;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
color: #0096ff;
}
.menu ul li ul {
padding: 0;
position: absolute;
background-color: rgba(0,0,0, 0.5);
margin-top: 5px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.menu ul li ul li {
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
font-size: 16px;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0, 0.9); }
.menu ul li:hover ul {
color: #0096ff;
display: block;
opacity: 1;
visibility: visible;
text-decoration: none;
}
.menu ul li a {
color: #3d3d3d;
}
.menu ul li a:hover {
color: #0096ff;
}
.menu ul li ul li a {
color: #fff;
}
.menu ul li ul li a:hover {
color: #0096ff;
}
HTML:
<header>
<div class="wrapper">
<div id="clogo"></div>
<span class="menu">
<ul id="dropnav">
<li><a href="/forums/index.php" />Forums</a></li>
<li>Members
<ul>
<li>Member List</li>
<li>Staff List</li>
</ul>
</li>
<li>Donate<br>
<ul>
<li>Buycraft</li>
<li>Buy Credits</li>
<li>CL Plus</li>
</ul>
</li>
</ul>
</span>
</div>
</header>
Consider to use > selector in the CSS, so it only looks one level down the markup structure, no deeper. A demo that made similar to your style - http://jsfiddle.net/55nw4wmy/
.class ul li {
affects all levels of <li> inside.
}
.class > ul > li {
only affects the first level.
}
.class > ul > li > ul > li {
only affects the second level.
}
That way, you don't have to overwrite the rules continually. And for the drop down disappearing problem, see the comments in the demo link above.
The codes you shown work fine on my end, but from your code I suspect .menu ul li ul { margin-top: 5px; } could be the cause of such behavior. Currently it's working only because the first-level li have a bottom padding that is larger than 5px.
If by any chance the li in your homepage header doesn't have a bottom padding, then the top margin in the 2nd level ul will cause a 5px space between the li and the ul sublist inside it. When you move your mouse from the li to the sub list the mouse passes through that 5px space zone which doesn't belong to the list item and :hover loses its effect.
I would suggest changing that to .menu ul li ul { padding-top: 5px; }

CSS transition doesn't work in Firefox

I tried a lot and already searched in Google but I don't find a solution for my problem:
I made a jsfiddle for you to see my source-code: Click here for my Source Code
Everything works fine. But the transition doesn't work in Firefox.
Here is my Sourcecode because I have to post it too if I want to use a jsfiddle!
<nav>
<ul>
<li>Startseite</li>
<li>Projekte
<ul>
<li>Java / Bukkit</li>
<li>Webdesign</li>
<li>PHP | MySQL</li>
</ul>
</li>
<li>Kontakt</li>
<li>Über mich</li>
</ul>
<div class="clear"></div>
</nav>
// CSS down \\ HTML up
nav{
background: #333;
color: #fff;
padding: 5px;
}
nav ul{
padding: 0px;
margin: 0px;
list-style: none;
}
nav ul li{
float:left;
}
nav ul li a{
color: #fff;
background: #585858;
padding: 10px;
margin-right: 5px;
display: block;
text-decoration: none;
border: 1px solid white;
}
nav ul li a.active{
background: #373737;
}
nav ul li a:hover{
color: #333;
background: #fff;
border: 1px solid black;
}
nav ul li ul{
position: absolute;
height: 0px;
overflow: hidden;
}
nav ul li ul li{
float: none;
}
nav ul li:hover ul{
overflow: visible;
}
nav ul li:hover ul li a{
padding: 10px;
}
nav ul li ul li a{
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
-ms-transition: 0.3s;
-o-transition: 0.3s;
transition: 0.3s;
padding: 0px 10px;
}
It looks like removing the overflow:hidden from the container suddenly makes the transition work. This leads me to believe it's an "optimisation" in Firefox that doesn't compute the "hidden" element.
Personally, I've used this to produce a similar effect: Rather than hiding the element, give it transform:scaleY(0); normally, and transform:scaleY(1); on hover.