Issue with dropdown menu using only css - html

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)

Related

Diagonal lines in UL

I'm pretty new to coding so please keep that in mind.
So I'm working on a little website, and I'm trying to stylise the header and nav bar. I'm trying to do some diagonal lines to seperate the different items in it, but I can't seem to make them appear.
I'd like to do something like this, with a simple drop shadow.
So here's my HTML and CSS
<nav>
<div class="logo"></div>
<ul>
<li>Home</li>
<li>Game</li>
<li>Infos</li>
<li>Contact</li>
<li><a class="active" href="#help">Help</a></li>
</ul>
</nav>
And
nav ul{
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
list-style: none;
}
nav ul li a {
line-height: 80px;
color: #151515;
padding: 12px 30px;
text-decoration: none;
text-transform: uppercase;
transition: .3s;
}
nav ul li a:hover{
color: #F16918;
text-shadow: 2px;
}
To be clear, everything in the image is already done and coded, except for the diagonal lines that I painted over in Photoshop.
My header switch to black when scrolling (white on top over the image), so that's why the text never says its black, but it is in the image.
So I was wondering if anyone could help me get those diagonal lines?
Thanks a lot!
Try this (using pseudo element)..adjust at your needs.
CSS
nav ul{
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
list-style: none;
position: relative;
}
nav ul li:after {
position: absolute;
content:"";
width: 1px;
height:100%;
background: #000;
transform: rotate(-45deg);
top:0;
left:0;
}
nav ul li a {
line-height: 80px;
color: #151515;
padding: 12px 30px;
text-decoration: none;
text-transform: uppercase;
transition: .3s;
}
nav ul li a:hover{
color: #F16918;
text-shadow: 2px;
}
CSS WITH SHADOW
nav ul li:after {
position: absolute;
content:"";
width: 1px;
height:100%;
background: transparent;
transform: rotate(-45deg);
top:0;
left:0;
box-shadow: -4px 0 1px rgba(0,0,0,0.2);
}
HTML
<nav>
<div class="logo"></div>
<ul>
<li>Home</li>
<li>Game</li>
<li>Infos</li>
<li>Contact</li>
<li><a class="active" href="#help">Help</a></li>
</ul>
</nav>
DEMO HERE

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

Drop down menu button isn't coloured fully and there are strange gaps in between

I'm trying to fix my drop down menu but I'm having problems with the highlighted colour and the background colour/size.
When I hover it, it is not covering the full button with orange like I want it to and, it has some grey left in it from the background where I don't want it to be.
One of the issues may be the fact I'm using 2 style sheets for mobile and computer.
HTML:
<div id="nav">
<ul id="menu">
<li id="active">Home</li>
<li>About Revelstoke</li>
<li>Ticker Rates</li>
<li>Snow School
<ul id="sub-menu">
<li>Kids Lessons</li>
<li>Adult Lessons</li>
<li>First Tracks</li>
</ul>
</li>
<li>Weather</li>
<li>Gallery</li>
<li>Trail Maps</li>
<li>Contact Us</li>
</ul>
</div><!--close nav-->
CSS (computer):
#nav {
background-color:#eee;
height: 33px;
border-top: solid black 2px;
border-bottom: solid black 2px;
min-width: 1000px;
}
#nav #active a {
font-weight: bold;
color: #ffffff;
background-color: #0160a2;
padding: 5px 15px 8px 15px;
}
#nav ul {
text-align: left;
font-size: 18px;
background-color: #eee;
}
#nav ul li {
display: block;
position: relative;
float: left;
line-height: 24px;
}
#nav ul li a {
display:inline;
padding:5px 10px 8px 10px;
background-color: #eee;
}
#nav li ul {
display: none;
}
#nav li:hover ul {
display: block;
position: absolute;
margin-top: 6px;
padding: 0;
width: 97px;
height: 82px;
}
#nav li:hover li {
font-size: 14px;
}
#nav ul li a:hover {
background-color: #ff8a00;
color: #000000;
}
#nav ul li ul li a{
padding:5px;
}
#nav ul li ul li a:hover{
padding:5px;
width: 97px;
height: 82px;
}
CSS (mobile):
#nav {
background-color:#eee;
}
#nav ul {
text-align:center;
font-size: 18px;
}
#nav ul li {
list-style-type:none;
border-top: 3px solid white;
}
#nav ul li a {
color: #000000;
display:block;
padding:13px 0;
text-decoration:none;
font-weight: bold;
}
#nav ul li a:hover {
background-color: #0096ff;
font-weight: bold;
color: white;
}
#nav #active a {
background-color: #01385e;
font-weight: bold;
color: white;
}
If I understood your question this should be a solution http://jsfiddle.net/GcDGv/2/ (I worked only for non-mobile CSS), this is how I fixed it:
I removed all height properties from classes related to the sub-menu. They can be auto-calculated.
Change the width of li elements in sub-menu to 100%, so now they will use whole area.
Make links in sub-menu as block elements, so margin/paddings from top and bottom will work as you want. And removed width and height properties from last style ul li ul li a:hover

Dropdown menu acting weird in IE 9

We have made a dropdown menu for our website and we just have to try it out in different browsers. The dropdown menu works flawlessly in Chrome and Firefox, but in Internet Explorer 9
it acts weird. Here's the problem: Whenever you hover inbetween the space between li's the primary dropdown list shows up. Here's the html code.
<nav>
<ul>
<li class="mainLi"> Matematik
<ul>
<li>Geometri</li>
<li>Algebra</li>
<li>Statistik</li>
</ul>
</li>
<li class="mainLi"> C#
<ul>
<li>Variabler</li>
<li>Villkor</li>
<li>Upprepning</li>
</ul>
</li>
<li class="mainLi"> HTML
<ul>
<li>Taggar</li>
<li>CSS</li>
</ul>
</li>
</ul>
</nav>
Here's the CSS:
.mainLi {
margin-left: 40px;
}
nav ul li {
border-right: 0px solid black;
border-left: 0px solid black;
float: left;
}
nav ul ul {
display: none;
background: #5f6975;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
margin-left: 0%;
}
nav ul li:hover > ul {
display: inline;
}
nav ul ul li a {
color: #fff;
font-size: 21px;
padding: 0.5px 5px;
text-align: center;
}
nav ul ul li a:hover {
background: #4b545f;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
border-right: 0;
border-left: 0;
position: relative;
list-style-type: none;
top: 100%;
}
nav ul li a {
display: block;
text-decoration: none;
color: black;
font-size: 25px;
}
nav > ul > li:hover > a {
display: block;
}
nav > ul > li:hover {
background: rgb(183,208,226); /* Old browsers */
}
JS Fiddle:
http://jsfiddle.net/K5JGE/
Here is the Solution.
The HTML:
<nav>
<ul>
<li class="mainLi"> Matematik
<ul>
<li>Geometri</li>
<li>Algebra</li>
<li>Statistik</li>
</ul>
</li>
<li class="mainLi"> C#
<ul>
<li>Variabler</li>
<li>Villkor</li>
<li>Upprepning</li>
</ul>
</li>
<li class="mainLi"> HTML
<ul>
<li>Taggar</li>
<li>CSS</li>
</ul>
</li>
</ul>
</nav>
The CSS:
.mainLi {
margin-left: 40px;
}
nav ul li {
border-right: 0px solid black;
border-left: 0px solid black;
float: left;
position:relative;
}
nav ul ul {
display: none;
background: #5f6975;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
margin-left: 0%;
}
nav ul li:hover > ul {
display: inline;
}
nav ul ul li a {
color: #fff;
font-size: 21px;
padding: 0.5px 5px;
text-align: center;
position:relative;
}
nav ul ul li a:hover {
background: #4b545f;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
border-right: 0;
border-left: 0;
position: relative;
list-style-type: none;
top: 100%;
}
nav ul li a {
display: block;
text-decoration: none;
color: black;
font-size: 25px;
}
nav > ul > li:hover > a {
display: block;
}
nav > ul > li:hover {
background: rgb(183,208,226); /* Old browsers */
}
You just needed to position the child elements accordingly. Thats it.
Hope this Helps.
Also if you take the nav ul ul top:100%; off, it will work too.
That one is working for sure #Nathan Lee.
Aswell you can use this "Template" or whatever you want to call it and make it to your own.
Well, that's what I always do!
DropDownMenu
It's what I use from PSDCenter. (from George Orsmond)
Hope this works good for you too!
Add position: relative; in nav ul li.

Adding a border-bottom: 1px solid #FFF to Index (top menu only) on hover in CSS Horizontal Drop Down Menu

I can't seem to figure as to how to add a border-bottom: 1px solid #FFF to all the top menu (index) items when hovered?
#menu{
padding:0;
margin:0;
position: fixed;
top: 30px;
left: 0px;
font-size: 8pt;
}
#menu ul{
padding:0;
margin:0;
}
#menu li{
position: relative;
float: left;
list-style: none;
margin: 0;
padding:0;
}
#menu li a{
width:120px;
height: 20px;
display: block;
text-decoration:none;
line-height: 20px;
background-color: #A9BBD3;
color: #FFF;
}
#menu li a:hover{
background-color: #446087;
}
#menu ul ul{
position: absolute;
top: 20px;
visibility: hidden;
}
#menu ul ul li a {
width: 115px;
padding-left: 5px;
}
#menu ul li:hover ul{
visibility:visible;
}
#menu > ul > li > a {
text-align:center;
}
<div id="menu">
<ul>
<li>File
<ul>
<li>Save</li>
<li>Link 1-2</li>
<li>Link 1-3</li>
</ul>
</li>
<li>Edit
<ul>
<li>Add</li>
<li>Delete</li>
</ul>
</li>
<li>Reports
<ul>
<li>Link 3-1</li>
<li>Link 3-2</li>
<li>Link 3-3</li>
</ul>
</li>
</ul>
<ul>
</div>
Use the css child selector to get the first one only:
/* NEW: This is the new style rule. */
#menu > ul > li > a:hover {
border-bottom: 1px solid #FFF;
}
#menu ul ul {
position: absolute;
top: 21px; /* <------ Had to add a pixel */
visibility: hidden;
}
Demo: http://jsbin.com/aciceg/1/
Source: http://jsbin.com/aciceg/1/edit
#menu ul ul{
position: absolute;
top: 21px;
visibility: hidden;
}
Change top to 21px for this one.
To put the border only on the top-level elements, use the direct descendant selector to make this rule:
#menu > ul > li > a:hover { border-bottom: 1px solid #fff; }
Then to make your new border visible, and not covered up by the submenus, move the submenus down by one pixel: change top: 20px to top: 21px in #menu ul ul.