Nav dropdown freaks out and shows different tabs - html

I'm trying to create a navbar (already done) with a dropdown, but the dropdown keeps spazzing out when I hover over it :(
I made a JS Fiddle of what I've accomplished so far, and I was hoping for some help!
http://jsfiddle.net/kkpp6/
I think it might be due to the display: none; I used in one of the ul's or possibly due to a stupid typo but I can't figure out where!
As well as this, I can't figure out how to make a sub-menu for my sub-menus that already exist.. (so the desc tab has a submenu of swim squad which will also have a sub-menu of other things).. How would I do that? I can't figure out where I would start!
Cheers for all the help in advance!

Try like this: LINK
CSS:
.nav-wrap {
background-color: #125CC1;
text-align: center;
}
ul.navigation-bar li a {
color: #FFFFFF;
background-color: #125CC1;
text-align: center;
padding: 6px;
font-size: 12px;
text-decoration: none;
text-transform: uppercase;
}
ul.navigation-bar li a:hover {
background-color: #06398F;
}
ul.navigation-bar {
text-align: left;
display: inline;
margin: 0;
list-style: none;
}
ul.navigation-bar li {
line-height:28px;
margin-right: -4px;
position: relative;
display: inline-block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: #125CC1;
text-align: center;
}
ul.navigation-bar li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: 120px;
-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;
}
ul.navigation-bar li ul li {
background: #125CC1;
display: block;
color: #fff;
}
ul.navigation-bar li ul li:hover {
background: #06398F;
color: #fff;
}
ul.navigation-bar li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
Updated fiddle LINK
Multi-level dropdown menu LINK

On line 38, you set a list to display when the user hovers over a list item. This makes it visible, but also causes the entire menu to shift over so that you're no longer hovering over the list item that triggered that. If you use position:absolute on the list, it won't affect the other elements on the page:
ul.navigation-bar li > ul {
position:absolute;
}
JSFiddle: http://jsfiddle.net/P9SUg/

I also think its because of display:none;, instead of display:none; you should use visibility:hidden;.
and also add
ul.navigation-bar li > ul {
position:absolute;
}

You need to do lot of changes in CSS for making dropdown menu.
.nav-wrap {
background-color: #125CC1;
text-align: center;
}
ul.navigation-bar {
list-style-type: none;
margin: 0;
padding: 0;
}
ul.navigation-bar > li {
display: inline;
position:relative;
}
ul.navigation-bar > li > a {
display: inline-block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: #125CC1;
text-align: center;
padding: 4px;
font-size: 12px;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: all 0.15s linear;
-moz-transition: all 0.15s linear;
-o-transition: all 0.15s linear;
transition: all 0.15s linear;
}
ul.navigation-bar > li > a:hover {
background-color: #06398F;
}
ul.navigation-bar ul {
display: none;
}
ul.navigation-bar li:hover > ul {
display: block;
position:absolute;
top:23px;
background-color:#ff00ff;
z-index:10;
width:100%;
list-style-type: none;
margin: 0;
padding: 0;
}
ul.navigation-bar li ul li a
{
list-type:none;
text-align: left;
font-weight:normal;
padding: 4px;
font-size: 10px;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: all 0.15s linear;
-moz-transition: all 0.15s linear;
-o-transition: all 0.15s linear;
transition: all 0.15s linear;
}
ul.navigation-bar li ul li:hover
{
background-color:#000;
}
ul.navigation-bar li ul li:hover a
{
color:#fff;
}
FIDDLE DEMO

Related

css navigation bar positioning

I'm trying to make a navigation bar for a hobby website to display my photography and other interest's of mine, I'm having slight issues with the position of a drop-down bar I have.
I wanted to know how I would be able to position the drop down menu so when I hover over the music item it would show directly under it. I tried position: relevant, it did work but it shifted all the items to the left of it down to align with the drop down menu.
http://jsfiddle.net/daCrosby/Ly8wuws1/
body{
background-color: #333;
}
nav ul {
list-style: none;
margin: 10px;
padding: 0;
font-family: 'Roboto', sans-serif;
font-weight: bold;
}
nav li {
display: inline-block;
margin: 0 5px;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
nav a {
color: black;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
nav a:hover {
color: #12242d;
}
nav span {
display: block;
color: rgba(255,255,255,0.6);
}
.Inav ul {
list-style: none;
margin-top: 20%;
padding: 0;
text-align: left;
top: 0;
left: 0;
position: fixed;
right: 0;
text-align: center;
font-family: 'Roboto', sans-serif;
font-weight: bold;
}
.Inav nav ul li {
display: inline-block;
margin: 0 5px;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
.Inav nav a {
color: black;
position: block
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
text-decoration: none;
}
.Inav nav a:hover {
color: #12242d;
}
.Inav nav span {
color: rgba(255,255,255,0.6);
}
.Inav ul li:hover ul{
display: block;
margin: 0px;
padding: 0px;
}
.Inav ul li ul{
display: none;
position: absolute;
}
.Inav ul li ul li{
display: block;
}
.Inav ul ul a{
color: white;
}
<div class="Inav">
<nav>
<ul>
<li><span>Home</span></li>
<li><span>FAQ</span></li>
<li><span>Honesty</span></li>
<li><span>Rand2</span></li>
<li><span>Rand3</span></li>
<li><span>Music</span>
<ul>
<li>Kanye</li>
<li>Drake</li>
</ul>
</li>
</ul>
</nav>
</div>
You need to add position: relevant to the parent list items, then add positioning top and left on the sub menu.
nav li {
position: relative;
}
.Inav ul li ul{
position: absolute;
top: 100%; /* modify as necessary */
left: 0px; /* modify as necessary */
}
http://jsfiddle.net/daCrosby/Ly8wuws1/1/

Navigation Menu Shrinks with Browser Sizing - CSS Issue

I created a navigation menu for a re-design of a website that's a Printing Company. Everything is working perfectly, but I can't find out why the Navigation shrinks when you change the browser size. I've created these menus before, and I've never had a problem with shrinking.
Here is the Demo https://jsfiddle.net/dshojaei/vbcztkdy/3/embedded/result/
#nav_wrap {
text-align: center;
background-color:#343232;
border-top:1px solid black;
height:54px;
}
/* Reset */
.nav,
.nav a,
.nav ul,
.nav li,
.nav div,
.nav form,
.nav input {
margin: 0;
padding: 0;
border: none;
outline: none;
}
.nav a { text-decoration: none; }
.nav li { list-style: none; }
/* Menu Container */
.nav {
display: inline-block;
position: relative;
cursor: default;
z-index: 500;
text-align:left;
}
/* Menu List */
.nav > li {
display:block;
float: left;
}
/* Menu Links */
.nav > li > a {
position: relative;
display: block;
z-index: 510;
height: 54px;
padding: 0 20px;
line-height: 54px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #fcfcfc;
text-shadow: 0 0 1px rgba(0,0,0,.35);
background: #343232;
border-left:none;
border-right:none;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.businesscards:hover > a {
background:#009ad6;
}
.flyers:hover > a{
background:#c60077;
}
.cards:hover > a {
background:#cec41e;
}
.banner:hover > a {
background:#000000;
}
.dvd:hover > a {
background:#3c3c3c;
}
.stationary:hover > a {
background:#7b7b7b;
}
.labels:hover > a {
background:#afafaf;
}
.catalogs:hover > a {
background:#d7d7d7;
}
.nav > li:first-child > a {
border-radius: 0px 0 0 0px;
border-left: none;
}
/* Menu Dropdown */
.nav > li > div {
position: absolute;
display: block;
width: 100%;
top: 55px;
left: 0;
opacity: 0;
visibility: hidden;
overflow: hidden;
border-right:1px solid black;
border-left:1px solid black;
border-bottom:1px solid black;
background: #ffffff;
border-radius: 0 0 3px 3px;
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
}
.nav > li:hover > div {
opacity: 1;
visibility: visible;
overflow: visible;
}
/* Menu Content Styles */
.nav .nav-column {
float: left;
width: 20%;
padding: 2.5%;
}
.nav .nav-column h3 {
margin: 20px 0 10px 0;
line-height: 18px;
display:inline;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 14px;
color: #372f2b;
text-transform: uppercase;
}
/*.nav .nav-column img {
display:inline;
width:20%;
height: 20%;
}
*/
.nav img:nth-of-type(1) {
margin-top:30px;
margin-left:20px;
float:left;
width:5%;
height:5%;
}
.nav img:nth-of-type(2) {
margin-top:30px;
margin-left:20px;
float:left;
width:5%;
height:5%;
}
#brochure {
margin-top:30px;
margin-left:20px;
float:left;
width:3%;
height:3%
}
.nav .nav-column h3.orange { color: #ff722b; }
.nav .nav-column li a {
display: block;
line-height: 26px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 13px;
color: #888888;
}
.nav .nav-column li a:hover { color: #666666; }
fix the width.
.nav {
display: inline-block;
position: relative;
cursor: default;
z-index: 500;
text-align: left;
width: 1190px;
}
You can change the code for the list items to the following:
.nav > li {
display: inline-block;
}
And, add the following declaration to the list rule set:
.nav {
display: inline-block;
position: relative;
cursor: default;
z-index: 500;
text-align:left;
white-space: nowrap;
}
In order, for this to display properly, the list items, in HTML, should be next to each other, otherwise you'll see spaces:
<ul><li></li><li></li></ul>

CSS Navigation Bar Active Link

I'm creating a website, and currently I am having issues with my navigation bar. The issue I am having is with the active link. The background won't fit to the size of the initial button like I want it to. The background is just highlighting the text basically.
<div class="nav">
<ul>
<li>Home</li>
<li><a class="active" href="cage-habitat.html">Cage & Habitat</a>
<ul>
<li>Litter Training</li>
</ul>
</li>
<li>Food & Treats</li>
<li>Dust Bath & Care</li>
<li>Safe Toys</li>
<li>Chinquiry</li>
</ul>
</div>
.nav {
background-color: #526655;
}
.nav a {
color: #fff;
text-decoration: none;
}
.nav ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
.nav ul li {
color: #fff;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #526655;
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;
}
.nav ul li:hover {
background: #94b399;
color: #fff;
}
/* drop down styles */
.nav ul li ul {
padding: 0;
position: absolute;
top: 42px;
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 ul li ul li {
background: #94b399;
display: block;
color: #fff;
}
.nav ul li ul li:hover {
background: #94b399;
}
.nav ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
/* end dropdown styles */
.active {
background: #94b399;
}
Any help would be appreciated. https://jsfiddle.net/cweav3r/7j25e8jh/
<ul><li><a href="litter-train-chinchilla.html">Litter
Training</a></li></ul> is taking extra space .
DEMO : http://jsfiddle.net/b89kds70/10/
<div class="nav">
<ul>
<li>Home</li>
<li><a class="active" href="cage-habitat.html">Cage & Habitat</a>
</li>
<li>Food & Treats</li>
<li>Dust Bath & Care</li>
<li>Safe Toys</li>
<li>Chinquiry</li>
</ul>
</div>
.nav {
background-color: #526655;
}
.nav a {
color: #fff;
text-decoration: none;
}
.nav ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
position:relative;
}
.nav ul li {
color: #fff;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #526655;
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;
}
.nav ul li:hover {
background: #94b399;
color: #fff;
}
/* drop down styles */
.nav ul li ul {
padding: 0;
position: relative;
top: 42px;
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 ul li ul li {
background: #94b399;
display: inline;
color: #fff;
}
.nav ul li ul li:hover {
background: #94b399;
}
.nav ul li:hover ul {
position:absolute;
display: block;
opacity: 1;
visibility: visible;
}
/* end dropdown styles */

Make CSS menu responsive and each item certain width

I am using this CSS Code for a HTML menu:
#CustomerMenu {
margin-bottom:35px;
}
#CustomerMenu ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(243, 111, 37, 5);
-moz-box-shadow: 0 0 5px rgba(243, 111, 37, 5);
box-shadow: 0 0 5px rgba(243, 111, 37, 5);
}
#CustomerMenu ul li {
display: inline-block;
position:relative;
}
#CustomerMenu ul li a {
font: bold 12px/18px Arial;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #FFFFFF;
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;
}
#CustomerMenu ul li a:hover {
background: #F36F25;
color: #FFFFFF;
}
#CustomerMenu ul li:hover > a {
background-color: #F36F25;
color: #FFFFFF;
}
#CustomerMenu ul li ul {
padding: 0;
position: absolute;
z-index:999;
top: 34px;
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;
}
#CustomerMenu ul li ul li a {
background: #666666;
display: block;
color: #FFFFFF;
width:100px;
}
#CustomerMenu ul li ul li a:hover {
background: #F35F25;
}
#CustomerMenu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
i want to make each <li> link a certain width whether it be a percentage or fixed
Also, can i make the menu responsive, whats the best jway to do this?
http://jsfiddle.net/ko69pyLz/
Use media queries
i am not adding full code, just showing how you can proceed, there are plenty of tutorials available in online.
#media screen and (min-width:0px) and (max-width:480px),
screen and (min-device-width:0px) and (max-device-width:480px){
#CustomerMenu ul li {
display: block;
}
#CustomerMenu ul li a {
font: bold 24px/36px Arial;
}
}
JSfiddle - resize the browser to atake effect
http://jsfiddle.net/ko69pyLz/5/
As the user Manjunath Siddappa stated, I'm not adding full code, or in this case, my example won't be using your code.
For the sizing part of it, you will need to use media queries, but since you want a mobile nav, you most likely want it to pull up into one large drop down bar, and that's where this comes in..
This code will help you create a mobile nav that can get vertically stacked/hidden, and then uses a onClick jQuery function to open and close the options.
JsFiddle: http://jsfiddle.net/qy6a185b/

Dropdown CSS issue - hidden list shows up when hovered over

my problem is that when I hover over the area where the hidden list is, it shows the hidden list. I only want it to show the hidden list when hovered over the 'Language' link on the dropdown menu. Why is it doing this, it's probably something blindingly obvious that I can't spot.
Cheers :)
EDIT: I've already tried using a fixed height for the #lang_bar. I also need the transitions to still work. I've already tried using the display:none and display:block; but that didn't work so I used visibility instead.
Any ideas?
HTML:
<div id="lang_bar">
<ul>
<li><strong>Language</strong>
<ul>
<li><strong>Maori</strong></li>
<li><strong>Tongan</strong></li>
<li><strong>Chinese</strong></li>
<li><strong>Japanese</strong></li>
<li><strong>Korean</strong></li>
</ul>
</ul>
</div>
#lang_bar {
font-family: 'Open Sans', sans-serif;
color: white;
padding-left: 152px;
text-transform: uppercase;
z-index: 40;
position: absolute;
padding-top: 2px;
top: 0;
}
#lang_bar ul ul li a {
padding-top: 3px;
padding-left:5px;
}
#lang_bar ul li ul li a:before {
content: '';
display:block;
right: 0px;
height: 2px;
bottom:117px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.2);
}
#lang_bar ul li ul li a:after {
content: '';
display:block;
right: 1px;
height: 2px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.6);
}
#lang_bar li, #lang_bar li ul {
text-decoration: none;
list-style-type: none;
}
#lang_bar ul {
list-style: none;
padding-left: 0px;
}
#lang_bar ul li {
float: left;
width: 100px;
text-align: left;
line-height: 21px;
}
#lang_bar ul li a {
display: block;
color: #FFF;
background: transparent;
text-decoration: none;
text-align: center;
}
#lang_bar ul li ul {
visibility: hidden;
font-size:12px;
opacity: 0;
}
#lang_bar ul li:hover ul {
opacity: 1;
visibility: visible; /* display the dropdown */
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#lang_bar ul li ul a:hover{
transition-duration: 0.6s;
background-color: rgba(255, 0, 0, 0.23);
}
I changed your css a little bit and here is the result
I used display:none and display: block in place of visibility, and everything is working as it should be.
http://jsfiddle.net/sy3qowxs/5/enter link description here
And here is your final CSS:
#lang_bar {
font-family: 'Open Sans', sans-serif;
color: #123111;
padding-left: 152px;
text-transform: uppercase;
z-index: 40;
position: absolute;
padding-top: 2px;
top: 0;
}
#lang_bar a:link{color:#333333;}
#lang_bar ul ul li a {
padding-top: 3px;
padding-left:5px;
}
#lang_bar ul li ul li a:before {
content: '';
display:block;
right: 0px;
height: 2px;
bottom:117px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.2);
}
#lang_bar ul li ul li a:after {
content: '';
display:block;
right: 1px;
height: 2px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.6);
}
#lang_bar li, #lang_bar li ul {
text-decoration: none;
list-style-type: none;
}
#lang_bar ul {
list-style: none;
padding-left: 0px;
}
#lang_bar ul li {
float: left;
width: 100px;
text-align: left;
line-height: 21px;
}
#lang_bar ul li a {
display: block;
color: #FFF;
background: transparent;
text-decoration: none;
text-align: center;
}
#lang_bar ul li ul {
display: none;
font-size:12px;
opacity: 0;
}
#lang_bar ul li:hover ul {
opacity: 1;
display: block; /* display the dropdown */
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#lang_bar ul li ul a:hover{
transition-duration: 0.6s;
background-color: rgba(255, 0, 0, 0.23);
}
As an alternative to the display: none solution, for accessibility reasons you can use position:absolute and then move the hidden element off screen:
ul li ul {
position:absolute;
top:-1000px;
}
ul li:hover ul {
top:auto;
}
It should work with visibility, since it hides the element (like display: none) but doesn't remove it from the DOM
Here is a working example: Dropdown Menu
HTML
<ul class="menu">
<li class="menu-item"> Dropdown Menu
<ul class="submenu">
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
</ul>
</li>
</ul>
CSS
.menu-item {
position: relative;
}
.menu-item:hover .submenu {
visibility: visible;
opacity: 1;
}
.submenu {
position: absolute;
visibility: hidden;
transition: all .2s ease;
opacity: 0;
top: 100%;
}
.submenu-item {
padding: .4em;
}
What about just using the adjacent sibling combinator:
Change: #lang_bar ul li:hover ul
To: #lang_bar ul li a:hover + ul
To add to the previous answer, the reason this works when you use the display property instead of visibility is because display removes the element from the document flow, and other elements reflow in its place. Visibility, on the other hand, hides the element, but leaves the empty space as if it were still there. So when you used visibility: hidden, your list item looked like it just contained the text "Language" and the link, but the hidden ul was still there, and still hoverable. That's why when you hovered over where the list item should have been, it reappeared; technically, you were hovering over that first list item, because the sub menu was a child of it.
In general, I use display:block/display:none to toggle hiding and showing of items, rather than visibility. Typically the use case is that you want the element completely hidden from the page, and elements around it to reflow, and the display property will do that for you.