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
Related
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;}
I have created a menu with a submenu which can be seen here: JSFIDDLE.
I created a triangle on top of my submenu but due to the fact that the submenu is shown when the menu item is hovered, undesired behaviour is shown.
If you want to click on one of the submenu's the submenu will be set to: display:none due to the fact that there is no hover detection anymore.
I think it is a quite simple fix and perhaps there is already a related question on this topic. but i would really appreciate any help.
*{
margin:0;
padding:0;
}
.menu nav{
text-align:center;
}
.menu nav ul{
list-style-type:none;
}
.menu nav ul li{
display:inline-block;
padding:80px 15px 0px 15px;
font-family: Titillium Web;
font-weight:700;
font-size:16px;
color:#00adef;
text-transform: uppercase;
}
.menu nav ul li a{
color:#00adef;
}
.menu nav ul li:hover{
border-bottom:4px solid #00adef;
}
.menu nav ul li .submenu{
display:none;
position: absolute;
background-color:#1A98C8;
margin-top:15px;
z-index:10;
opacity:0.9;
left:38%;
}
.menu nav ul li .submenu:before{
content: '';
position: absolute;
left: 75px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #1A98C8;
}
.menu nav ul li .submenu li{
color:#fff;
display:block;
padding-top:0px;
padding-left:0px;
height:40px;
border-bottom:1px solid #fff;
opacity:1;
line-height:40px;
width:150px;
}
.menu nav ul li:hover .submenu{
display:block;
}
<div class="menu">
<nav>
<ul class="default-menu">
<li>Home</li>
<li>about</li>
<li>
submenu <i class="fa fa-angle-right" aria-hidden="true"></i>
<ul class="submenu">
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
</li>
<li>Testimonials</li>
<li>Contact</li>
</ul>
</nav>
</div>
What you need to do here is basically add a delay for your .submenu to open so that when you navigate from your li to the .submenu, the .submenu is still open.
You can add that delay using the transition property as in:
.menu nav ul li .submenu {
transition: all .1s;
}
Since you would be using transition, you can't use the display property since it does not reflect a state change. Use a combination of visibility and opacity to achieve the hide and show behaviour of display.
Refer code:
* {
margin: 0;
padding: 0;
}
.menu nav {
text-align: center;
}
.menu nav ul {
list-style-type: none;
}
.menu nav ul li {
display: inline-block;
padding: 80px 15px 0px 15px;
font-family: Titillium Web;
font-weight: 700;
font-size: 16px;
color: #00adef;
text-transform: uppercase;
}
.menu nav ul li a {
color: #00adef;
}
.menu nav ul li:hover {
border-bottom: 4px solid #00adef;
}
.menu nav ul li .submenu {
visibility: hidden;
opacity: 0;
position: absolute;
background-color: #1A98C8;
margin-top: 15px;
z-index: 10;
opacity: 0.9;
left: 38%;
transition: all .1s;
}
.menu nav ul li .submenu:before {
content: '';
position: absolute;
left: 75px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #1A98C8;
}
.menu nav ul li .submenu li {
color: #fff;
display: block;
padding-top: 0px;
padding-left: 0px;
height: 40px;
border-bottom: 1px solid #fff;
opacity: 1;
line-height: 40px;
width: 150px;
}
.menu nav ul li:hover .submenu {
visibility: visible;
opacity: 1;
}
<div class="menu">
<nav>
<ul class="default-menu">
<li>Home</li>
<li>about</li>
<li>
submenu <i class="fa fa-angle-right" aria-hidden="true"></i>
<ul class="submenu">
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
</li>
<li>Testimonials</li>
<li>Contact</li>
</ul>
</nav>
</div>
Instead of using
display: none;
Try using
visibility:hidden
display:none means that the tag in question will not appear on the page at all (although you can still interact with it through the dom). There will be no space allocated for it between the other tags.
visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn't seen on the page.
Found this on this question on stackoverflow. I think this could solve your issue of not being able to detect the :hover event (because 'display: none' removes the element)
I have a top navigation bar with 4 options, where I wish that while the fourth option is hovered, a dropdown-menu will display.
The navigation bar is an unordered list, and the dropdown-menu (which should be activated by the fourth option) is a div consisting of 3 links.
The list item that is supposed to display the dropdown-menu while hovered:
<li class="dropdownbutton">Contact</li>
With the help of this line of code:
.dropdownbutton:hover .dropdowncontent {
display:inline-block;
}
And this is the CSS for the dropdown-content:
.dropdowncontent {
display:none;
background-color:#333;
margin-left:272px;
width:90px;
text-align:center;
}
What am I missing?
This should be allright.
ul {
margin: 0;
padding: 0;
list-style: none;
background-color: #333;
}
ul li {
display: inline-block;
position: relative;
text-align: left;
background-color: #333;
}
ul li a {
display: block;
color: #f2f2f2;
text-align: center;
padding: 16px 15px;
text-decoration: none;
transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
font-size: 17px;
font-family: Arial;
}
ul li a:hover {
background-color: #555;
}
ul li ul.dropdown {
min-width: 100%;
display: none;
position: absolute;
z-index: 999;
left: 0;
width: 90px;
}
ul li:hover ul.dropdown {
display: block;
}
ul li ul.dropdown li {
display: block;
}
ul li ul.dropdown li a {
font-size: 14px;
padding: 10px 15px;
}
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>Contact
<ul class="dropdown">
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</li>
</ul>
I want it to like like this image (Works like this in Google Chrome, Opera, and Safari):
However, in Firefox and the latest version of IE, it looks like this:
HTML:
<div id="navbar">
<ul>
<li class="selected">
HOME
</li>
<li>
OUR FACILITIES
</li>
<li>
ABOUT US
<ul>
<li>
MEET THE STAFF
</li>
</ul>
</li>
<li>
CONTACT US
<ul>
<li>
RESERVATIONS
</li>
<li>
DIRECTIONS
</li>
</ul>
</li>
</ul>
</div>
CSS:
#navbar {
margin-top: 87px;
}
#navbar ul {
list-style: none;
background-color: transparent;
}
#navbar ul li {
font-family: magic;
font-size: 1.6em;
background-color: #85CE85;
display: inline-block;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 45px;
padding-right: 45px;
}
#navbar .selected {
background-color: #CCFFCC;
}
#navbar ul li ul {
display: none;
background-color: transparent;
width: 245px;
height: 130px;
margin-top: 20px;
margin-left: -85px;
font-family: SkyHaven;
font-size: .7em;
}
#navbar ul li:hover > ul {
display: inline-block;
position: fixed;
}
#navbar ul li ul li {
width: 175px;
border-top: 1px black dashed;
background-color: #85CE85;
}
#navbar ul li ul li:hover {
background-color: #6699FF;
}
#navbar ul li a {
text-decoration: none;
color: black;
font-weight: bold;
}
#navbar a:hover {
color: white;
transition: .2s;
}
#navbar li:hover {
background-color: #CC0000;
transition: .8s;
}
Thanks for your help!
Changed this:
#navbar ul li:hover > ul {
display: block;
position: absolute;
}
Seems to be working for me in Firefox. How does it look for you? Fiddle
Is this what you were looking for?
http://jsfiddle.net/j22cG/
You need to position the submenu like so:
position:absolute;
top:100%;
left:0;
And position your parent li to relative.
Here is the new code it will work for you with no problems:
http://codepen.io/anon/pen/KpxaG/
As just and advice try to use html5shiv, to avoid IE problems:
html5shiv
Hi I am having trouble getting my vertical submenu to align directly under the parent horizontal menu. I only want the submenus to appear when they are hovered over. I have probably over complicated the entire CSS for myself. Any help would we very much appreciated
Here is the HTML code
<div id="nav_bar">
<ul>
<li>Home </li>
<li> About Us </li>
<li> Training
<ul>
<li> Funded Training</li>
<li> Traineeships</li>
<li> Fee for Service</li>
<li> Enterprise Specific Skill Sets</li>
<li> RPL Assessment</li>
<li> International Training</li>
</ul>
</li>
<li>
Employers
<ul>
<li> Existing Workers</li>
<li> New Workers</li>
</ul>
</li>
<li>Contact Us </li>
<li>Links</li>
</ul>
</div>
Here is the CSS
#nav_bar {
font-family: Verdana, Helvetica, Arial, sans-serif, serif;
font-size:1.2em;
font-weight:bold;
float: left;
height: 28px;
width: 689px;
margin-top: 40px;
margin-right: 20px;
margin-bottom: 0px;
margin-left: 10px;}
#nav_bar ul {
list-style-type:none;
margin:0px;
padding:0px;
overflow:hidden;}
#nav_bar li a:link, #nav_bar li a:visited {
float:left;
color: #000;
text-decoration: none;
display:block;
width: 106px;
text-align:center;
padding: 4px;
}
#nav_bar li a:hover, #nav_bar li a:active {
color: #FFF;
background-color: #184B8D;
}
#nav_bar li ul {
display: none;
position:absolute;
}
#nav_bar li ul a:link, #nav_bar li ul a:visited {
color:#000;
text-decoration:none;
display:inline-block;
width:auto;
text-align:center;
padding:4px;
}
#nav_bar li ul a:hover, #nav_bar li ul a:active {
display:block;
position: absolute;
}
#nav_bar li:hover ul {
display:block;
clear:both;
}
hey i can give example that i make refer this :)
add a class to the sub menu and apply style as follows
wish you good luck (Y)
<h2>Dropdown menu example</h2>
<nav class="cf">
<nav class="cf">
<ul class="topmenu">
<li>Home</li>
<li>Products
<ul class="submenu">
<li>Laptops</li>
<li>Tablets</li>
<li>Smartphones</li>
<li>Accessories</li>
</ul>
</li>
<li>Blog
<ul class="submenu">
<li>Recent articles</li>
<li>Archives</li>
<li>Hall of fame</li>
</ul>
</li>
<li>About</li>
<li>Contact
<ul class="submenu">
<li>Customer service</li>
<li>Register</li>
<li>Technical support</li>
</ul>
</li>
</ul>
</nav>
</nav>
CSS
/*micro-clearfix by Nicolas Gallagher http://nicolasgallagher.com/micro-clearfix-hack/*/
/* For modern browsers */
.cf:before, .cf:after {
content:"";
display:table;
}
.cf:after {
clear:both;
}
/* For IE 6/7 (trigger hasLayout) */
.cf {
zoom:1;
}
/*horizontal menu styles*/
nav {
background: #916A31;
height: 2.3em;
}
ul, li {
margin: 0;
padding: 0;
list-style: none;
float: left;
}
ul {
background: #D5973C;
height: 2em;
width: 100%;
}
li {
position: relative;
}
li a {
display: block;
line-height: 2em;
padding: 0 1em;
color: white;
text-decoration: none;
}
li a:hover, .topmenu li:hover > a {
background: #916A31;
height: 2em;
padding-top: .3em;
position: relative;
top: -.3em;
border-radius: .3em .3em 0 0;
}
.current, a:hover.current, .topmenu li:hover a.current {
background: #AD9B7F;
color: #eee;
padding-top: .3em;
border-radius: .3em .3em 0 0;
position: relative;
top: -.3em;
border-bottom: .3em solid #917F63;
cursor: default;
}
/*dropdown menu styles*/
ul.submenu {
float: none;
background: #916A31;
width: auto;
height: auto;
position: absolute;
top: 2em;
left: -9000em;
max-height: 0;
-moz-transition:max-height 0.5s ease-in-out;
-webkit-transition:max-height 0.5s ease-in-out;
-o-transition:max-height 0.5s ease-in-out;
transition:max-height 0.5s ease-in-out;
overflow: hidden;
}
ul.submenu li {
float: none;
}
.topmenu li:hover ul {
left: 0;
max-height: 10em;
}
ul.submenu li a {
border-bottom: 1px solid white;
padding: .2em 1em;
white-space: nowrap;
}
ul.submenu li:last-child a {
border-bottom: none;
}
ul.submenu li a:hover {
background: #D5973C;
height: 2em;
padding-top: .2em;
top: 0;
border-radius: 0;
}