Nav bar padding and margins not reacting as expected - html

There seems to be an issue with my dropdown class and li class formatting (specifically padding/margins) not interacting as expected. The two-page selections with dropdown menus are getting extra padding from somewhere when I add left margins in the li CSS. while trying to fix that issue I also discovered that the padding between the nav text (in li a) isn't acting right either. I'm not sure where to go from here as I'd like to add a logo to the left side of the nav but can't move the nav text around properly.
The StackOverflow built-in HTML CSS console runs it weird, so here's the CodePen link
/* Nav Bar and Logo*/
/* Logo */
.logo {
position: absolute;
margin: 20px 0px 0px 0px;
}
/* nav-bar color and placement*/
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #0d0d0d;
font-family: Verdana;
}
/* nav text side alighnment*/
li {
float: left;
margin-left: 100px;
}
/* nav text formating*/
li a {
display: block;
color: #98c94f;
text-align: center;
padding: 20px 20px;
text-decoration: none;
}
/* Hovering on nav */
li a:hover:not(.active),
.dropdown:hover {
background-color: #2a3b12;
transition: 0.5s;
}
/* Current page your in*/
.active {
background-color: #8bc33c;
color: black;
font-style: italic;
padding: 19px 39px;
font-size: 18px;
}
/* Far-side button*/
.booking {
background-color: #3231ab;
color: #f4f9ec;
}
/* drop-down text alighnment*/
.dropdown {
float: left;
overflow: hidden;
}
/* drop-down box format*/
.dropdown-content {
display: none;
position: absolute;
background-color: #d1e7b1;
min-width: 160px;
/* drop-down box shadow*/
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
/* drop box postion (directly under nav) */
top: 67.5px;
}
/* drop-down text format*/
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* drop-down hover color*/
.dropdown-content a:hover {
background-color: #bbdb8a;
transition: 0.3s;
}
/* actavates drop-down when hovering */
.dropdown:hover .dropdown-content {
display: block;
}
<ul>
<div class="logo">
<a herf="#"><img src="DJ_Turntable_LOGO_3.png"></a>
</div>
<li class="Home"><a class="active" href="Index.html">Home</a></li>
<div class="dropdown">
<li class="About">About</li>
<div class="dropdown-content">
My Story
</div>
</div>
<li class="Packages">Packages</li>
<div class="dropdown">
<li class="Events">Events</li>
<div class="dropdown-content">
Weddings
School Celebrations
Corporate Events
Special Occasions
</div>
</div>
<li class="Reviews">Reviews </li>
<li class="Gallery">Gallery </li>
<li class="Resourses">Resourses </li>
<li class="Contact">Contact </li>
<li style="float:right"><a class="booking" href="https:">Book Now!</a></li>
</ul>

Related

My dropdown menu isn't working properly, where am I going wrong?

I am a beginner to web development, and I am trying to make a dropdown menu.
The problem is when I hover on particular element, it consumes more than the expected space.
I want it to appear below the "shop" element. I do not understand where I am going wrong.
.nav {
width: 100%;
float: right;
}
.nav ul {
/* it edits the list, list-style: none; removes the discs from the list items */
float: right;
list-style-type: none;
display: block;
text-align: right;
}
.nav ul li {
display: inline-block;
margin: 20px 40px;
padding: 0 10px 0 10px;
text-align: center;
position: relative;
border: 2px solid gold;
}
.nav ul li a {
/* edits the links- text-decoration: none; removes the underline others are obvious*/
color: #000000;
text-decoration: none;
display: block;
}
.nav ul li ul li {
/* navigation sub-options disappear when not hovered */
display: none;
margin: 0;
padding: 0;
border: 2px solid greenyellow;
}
.nav ul li:hover ul li {
/* navigation options appear when hover on elements */
display: block;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Shop
<ul>
<li>Products</li>
<li>Membership</li>
</ul>
</li>
<li>Blog</li>
<li>News</li>
<li>Activity</li>
<li>Contact Us</li>
</ul>
</div>
Set position: relative on shop-link and position: absolute on dropdown. Then align dropdown with top, left, bottom, transform what would you like.
With transform it would look like this:
.link {
position: relative;
}
.dropdown {
position: absolute;
bottom: 0;
left: 0;
transform: translateY(100%)
}
I think the issue is with the way you organized these elements. Personally, when I make drop down menus, I use <button> for each root of the drop down menu. It makes styling everything much easier.
Then, what I do is I put the main text in an <h2> or <h3>, and style that how I want the main part of the drop down to look. Everything inside of the drop down can be styled using the <button> class' settings. Here's how I modified your code to get what I assumed your looking for.
CSS Styling:
.nav2 a {
color: #000000;
text-decoration: none;
display: block;
}
.nav2 button {
margin: 20px 40px;
padding: 0 10px 0 10px;
border: 0px;
/* change this to the color you want the background of your website to be */
background-color: white;
border: 2px solid gold;
font-size: 0px;
}
.nav2 button:hover {
display: inline-block;
margin: 20px 40px;
padding: 0 10px 0 10px;
text-align: center;
position: relative;
background-color: white;
border: 2px solid greenyellow;
/* change this to the color you want the background of your website to be */
background-color: white;
font-size: 16px;
}
h2 {
color: #000000;
text-decoration: none;
font-size: 16px;
font-weight: normal;
}
And then the HTML body:
<div class="nav2">
<button>
<h2>Home</h2>
</button>
<button>
<h2>Shop</h2>
<br>Products
<br>Membership
</button>
<button>
<h2>Blog</h2>
</button>
<button>
<h2>News</h2>
</button>
<button>
<h2>Activity</h2>
</button>
<button>
<h2>Contact Us</h2>
</button>
</div>
The end result looked like this
I hope my response was helpful!!
Your CSS is a bit messy, but to get it working add the following:
/* sub-nav option list */
.nav > ul > li > ul {
position: absolute;
margin-top: 1px; /* removes border intersection, can't be too large otherwise a gap will remove hover */
left: -55px;
}
position: absolute "removes" the element from the container so it is not contained in your parent's border. This will allow us to use the left, right, bottom, top CSS properties to position the sub-nav.
margin-top is used here to remove the intersection of shop and the sub-nav. However, you should be careful increasing this value greater than 1-2px since it will create empty space and hovering on the elements is required for your sub-nav to show.
Here is the working snippet:
.nav {
width: 100%;
float: right;
}
.nav ul {
/* it edits the list, list-style: none; removes the discs from the list items */
float: right;
list-style-type: none;
display: block;
text-align: right;
}
.nav ul li {
display: inline-block;
margin: 20px 40px;
padding: 0 10px 0 10px;
text-align: center;
position: relative;
border: 2px solid gold;
}
.nav ul li a {
/* edits the links- text-decoration: none; removes the underline others are obvious*/
color: #000000;
text-decoration: none;
display: block;
}
/* sub-nav option list */
.nav > ul > li > ul {
position: absolute;
margin-top: 1px; /* removes border intersection, can't be too large otherwise a gap will remove hover */
left: -55px;
}
.nav ul li ul li {
/* navigation sub-options disappear when not hovered */
display: none;
margin: 0;
padding: 0;
border: 2px solid greenyellow;
}
.nav ul li:hover ul li {
/* navigation options appear when hover on elements */
display: block;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Shop
<ul>
<li>Products</li>
<li>Membership</li>
</ul>
</li>
<li>Blog</li>
<li>News</li>
<li>Activity</li>
<li>Contact Us</li>
</ul>
</div>
Position docs for a better explanation of absolute: https://developer.mozilla.org/en-US/docs/Web/CSS/position
Here You have:
.nav{
position: relative;
display: flex;
justify-content: flex-end;
}
.nav ul{
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
}
.nav ul li{
background-color: gold;
border: 1px solid gold;
color: #FFF;
}
.nav ul li:hover{
background-color: #FFF;
color: gold;
}
.nav ul li a{
padding: 1rem 2rem;
color: inherit;
text-decoration: none;
font-family: Verdana;
}
.nav ul li ul {
/* navigation sub-options disappear when not hovered */
display: none;
opacity: 0;
visibility: hidden;
position: absolute;
margin: 0;
padding: 0;
border: 2px solid greenyellow;
}
.nav ul li:hover ul {
/* navigation options appear when hover on elements */
display: flex;
opacity: 1;
visibility: visible;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Shop
<ul>
<li>Products</li>
<li>Membership</li>
</ul>
</li>
<li>Blog</li>
<li>News</li>
<li>Activity</li>
<li>Contact US</li>
</ul>
</div>

Sub menu items keeps moving... How to make them fixed?

Ok, so here we go again...
The elements in my sub-menu keep moving when I hover over them. I can't seem to find anything on this issue. I've asked this question before for my nav bar but the answer I received- (Have the same padding for the a tags and put a border around them- but have it transparent) does not work with the sub-menu. I've tried to play with the padding as well with no luck.
Another thing...(I apologize for all questions, I just hate asking on here.. Some can be condescending) I had assign a class to each element (or list item) of the nav bar because when I attempted to put a border around them, each of the sub-menu elements also inherited the border as well. Is the a "cleaner" way to do it? I tried the :not() tag but I can't seem to get that to work either.
Lastly, I ask questions on this site as a last option. I am a newbie programmer/web designer who is looking to network and would like to connect with people who are more experienced before I get banned from asking a question that someone else sees as futile. If this last request is against the terms of service please let me know - I will delete it.
HTML
/* Style The Dropdown Button */
.dropbtn {
background-color: transparent;
font-family: 'Homemade Apple',cursive;
color: pink;
padding: 4px;
font-size: 16px;
cursor: pointer;
border: 3px solid pink;
border-radius: 16px;}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #DDDDEE;
border: 3px solid pink;
border-top: hidden !important;
border-radius: 16px;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 2;
}
/* Links inside the dropdown */
.dropdown-content a {
color: #B76E79;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {color: #B76E79}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown
content is shown */
.dropdown:hover .dropbtn {
color: #B76E79;
background-color: #DDDDEE;
}
</style>
</head>
<body>
<h1>Debi's Babies</h1>
<h2>A Mother's collection of Snow Babies</h2>
<ul class = "nav">
<li class= "one">Home</li>
<li class= "two">Original Figurines</li>
<li class= "three">Villages</li>
<div class = "dropdown">
<a href= "guest_collect.html"<button class="dropbtn">The Guest
Collection</button></a>
<div class = "dropdown-content">
<li class="c">Dr. Seuss</li>
<li class="d">Rudolph and Friends</li>
<li class="e">Santa</li>
<li class="f">Wizard of Oz</li>
</div>
</div>
</li>
<li class= "four">Oranments</li>
<li class= "five">Snow Bunnies</li>
</ul>
</body>
</html>
CSS
/*navbar*/
.nav {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
display: block;
position: relative;}
.nav li{
display: inline-block;
}
.nav a {
display: inline-block;
color: pink;
font-family: 'Homemade Apple', cursive;
padding: 6px;}
.nav li a:hover {
color: #B76E79;
padding: 8px;
z-index: 1;
}
.one,.two,.three,.four,.five {
border: 3px solid pink;
border-radius: 16px;}
.one:hover,.two:hover,.three:hover,.four:hover,.five:hover {
background: #DDDDEE;
}
As far as I can tell, the 'positioning' change you're talking about is coming from the additional padding on hover. This is specifically coming from the declaration:
.nav li a:hover {
padding: 8px;
}
Removing this solves the problem. However, in addition to this, your <a> tag is missing the >, and you have one </li> too many.
Both of those have also been corrected in the following example:
/* Style The Dropdown Button */
.dropbtn {
background-color: transparent;
font-family: 'Homemade Apple', cursive;
color: pink;
padding: 4px;
font-size: 16px;
cursor: pointer;
border: 3px solid pink;
border-radius: 16px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #DDDDEE;
border: 3px solid pink;
border-top: hidden !important;
border-radius: 16px;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 2;
}
/* Links inside the dropdown */
.dropdown-content a {
color: #B76E79;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
color: #B76E79
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown
content is shown */
.dropdown:hover .dropbtn {
color: #B76E79;
background-color: #DDDDEE;
}
/*navbar*/
.nav {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
display: block;
position: relative;
}
.nav li {
display: inline-block;
}
.nav a {
display: inline-block;
color: pink;
font-family: 'Homemade Apple', cursive;
padding: 6px;
}
.nav li a:hover {
color: #B76E79;
/*padding: 8px;*/
z-index: 1;
}
.one,
.two,
.three,
.four,
.five {
border: 3px solid pink;
border-radius: 16px;
}
.one:hover,
.two:hover,
.three:hover,
.four:hover,
.five:hover {
background: #DDDDEE;
}
<h1>Debi's Babies</h1>
<h2>A Mother's collection of Snow Babies</h2>
<ul class="nav">
<li class="one">Home</li>
<li class="two">Original Figurines</li>
<li class="three">Villages</li>
<div class="dropdown">
<a href="guest_collect.html"><button class="dropbtn">The Guest
Collection</button></a>
<div class="dropdown-content">
<li class="c">Dr. Seuss</li>
<li class="d">Rudolph and Friends</li>
<li class="e">Santa</li>
<li class="f">Wizard of Oz</li>
</div>
</div>
<li class="four">Oranments</li>
<li class="five">Snow Bunnies</li>
</ul>
As for your second question, you don't have to assign a class to each list item element. You can target the li directly. Depending on exactly which <li> elements you're trying to target, you can increase the specificity.
The problem for you is that .nav li won't work, as that will target any <li> element that is a child of .nav. In order to only target the direct children (excluding grandchildren), you need to make use the child combinator (>), with .nav > li.
Finally, I'm afraid that StackOverflow is a question-answer website, not a place to connect with other developers. If you're looking to connect to other programmers, there's no better place than StackOverflow Chat.
Hope this helps! :)
It is not correct use of div in ul, ul accepts li as children only.
See this: More
so, use li instead of div like this:
<li class = "dropdown">
<a href= "guest_collect.html">The Guest
Collection</a>
<ul class = "dropdown-content">
<li class="c">Dr. Seuss</li>
<li class="d">Rudolph and Friends</li>
<li class="e">Santa</li>
<li class="f">Wizard of Oz</li>
</ul>
</li>
And insert this css code:
li {
position: relative;
}
li:hover ul {
display: block;
padding: 0;
z-index: 999;
}
li ul {
position: absolute;
display: none;
list-style: none;
background-color: #DDDDEE;
border-radius: 5px;
top: 42px;
}
.nav li ul li {
width: 100%;
}
And other css codes:see code snippet
.nav {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
display: block;
position: relative;
margin: 0 auto;
width: 100%;
}
.nav li{
display: inline-block;
}
.nav a {
display: block;
color: pink;
font-family: 'Homemade Apple', cursive;
padding: 6px;}
.nav li a:hover {
color: #B76E79;
padding: 8px;
z-index: 1;
}
.one,.two,.three,.four,.five,.dropdown {
border: 3px solid pink;
border-radius: 16px;}
.one:hover,.two:hover,.three:hover,.four:hover,.five:hover,.dropdown:hover {
background: #DDDDEE;
}
li {
position: relative;
}
li:hover ul {
display: block;
padding: 0;
z-index: 999;
}
li ul {
position: absolute;
display: none;
list-style: none;
background-color: #DDDDEE;
border-radius: 5px;
top: 42px;
}
.nav li ul li {
width: 100%;
}
<h1>Debi's Babies</h1>
<h2>A Mother's collection of Snow Babies</h2>
<ul class = "nav">
<li class= "one">Home</li>
<li class= "two">Original Figurines</li>
<li class= "three">Villages</li>
<li class = "dropdown">
<a href= "guest_collect.html">The Guest
Collection</a>
<ul class = "dropdown-content">
<li class="c">Dr. Seuss</li>
<li class="d">Rudolph and Friends</li>
<li class="e">Santa</li>
<li class="f">Wizard of Oz</li>
</ul>
</li>
</div>
</li>
<li class= "four">Oranments</li>
<li class= "five">Snow Bunnies</li>
</ul>

Dropdown Menu Somehow Not Working

I have went through W3Schools to attempt understanding the coding structure of dropdown menus. When opening the page and hovering your cursor to the 'Merch' text it is supposed to display the dropdown menu. For some reason, however, it is not showing. Please amplify for me and show me where I went wrong.
<!DOCTYPE html>
<html>
<head>
<style>
ul {
margin: 0;
overflow: hidden;
background-color: dimgray;
list-style-type: none;
}
li {
float: left;
}
li a {
text-decoration: none;
font-family: sans-serif;
display: inline-block;
color: white;
padding: 12px;
}
li a:hover {
background-color: gray;
}
#dropdown {
position: absolute;
display: none;
background-color: darkgray;
min-width: 140px;
}
#dropdown a {
color: white;
text-align: left;
padding: 10px;
display: block;
text-align: left;
}
#dropdown a:hover {
background-color: gray;
}
#dropbtn:hover #dropdown {
display: block;
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>Merch
<div id="dropdown">
Shirts
Pants
</div>
</li>
<li>About Us</li>
</ul>
</body>
</html>
You need this change in CSS
#dropbtn:hover + #dropdown {
display: block;
}
Dropdown is not a child, it is next element in your current html setup, so, this selector will find it.
Or, better, place id on li element (parent):
<ul>
<li>Home</li>
<li id="dropbtn"><a href="#" >Merch</a>
<div id="dropdown">
Shirts
Pants
</div>
</li>
<li>About Us</li>
</ul>
#dropbtn:hover #dropdown {
display: block;
}
Demo: https://jsfiddle.net/3bfgzf37/
If you use first solution, dropdown dissapears fast, and behave strange...
Explanation: hover on a is not hover on dropdown (a is sibling), hover on li element, is, in the same time, hover on dropdown (parent-child, dropdown is 'inside' li - that produces consistent, desired, behavior).
Second one is better.
ul {
margin: 0;
overflow: hidden;
background-color: dimgray;
list-style-type: none;
}
li {
float: left;
}
li a {
text-decoration: none;
font-family: sans-serif;
display: inline-block;
color: white;
padding: 12px;
}
li a:hover {
background-color: gray;
}
#dropdown{
position: absolute;
display:none;
background-color: darkgray;
min-width: 140px;
}
#dropdown a {
color: white;
text-align: left;
padding: 10px;
display: block;
text-align: left;
}
#dropdown a:hover {
background-color: gray;
}
#dropbtn:hover #dropdown {
display: block;
}
<ul>
<li>Home</li>
<li id="dropbtn"><a href="#" >Merch</a>
<div id="dropdown">
Shirts
Pants
</div>
</li>
<li>About Us</li>
</ul>
<h3>Dropdown Menu inside a Navigation Bar</h3>
<p>Hover over the "Dropdown" link to see the dropdown menu.</p>
Your style tag should be outside the head tag. Plus, the dropdown in this code works now. Just do some slight changes to the colors to your desire. :)
<html>
<head></head>
<style>
ul {
margin: 0;
overflow: hidden;
background-color: dimgray;
list-style-type: none;
}
li {
float: left;
}
li a {
text-decoration: none;
font-family: sans-serif;
display: inline-block;
color: white;
padding: 12px;
}
/* Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: gray;
}
</style>
<body>
<ul>
<li>Home</li>
<li>
<div class="dropdown">
<button class="dropbtn">Merch</button>
<div class="dropdown-content">
Shirts
Pants
</div>
</div>
</li>
<li>About Us</li>
</ul>
</body>
</html>

Dropdown Menu covered by div

Hello I want to add a dropdown menu to my top navigation bar.
But for some reason it gets hidden by my image slider.
I would like the dropdown content to be on top of everything as it should be.
/* Style The Dropdown Button */
.dropbtn {
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
z-index: 999;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #565656;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #f1f1f1
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
<div id="header">
<ul>
<li>
<a class="a-no-hover" href="index.html">
<img src="images/miniLogo.png" />
</a>
</li>
<li><a class="active" href="index.html">HOME</a>
</li>
<div class="dropdown">
<li class="dropbtn">PRODUCTS
</li>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<li>ORDER
</li>
<li>ABOUT US
</li>
<li>CONTACT US
</li>
</ul>
</div>
<div id="section1">
<img id="img" src="images/bg.jpg" />
</div>
You are giving z-index to the header menu, that's fine. But the content is what is the problem. So, try giving z-index to the .dropdown-content:
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #565656;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1000; /* One more than the header. */
}
Update
#header ul {
list-style-type: none;
margin: 0;
padding: 0;
/* overflow: hidden; Remove this. */
text-align: center;
vertical-align: middle;
}
Preview
Output: http://jsbin.com/lorebubizi/1

Subnavbar drop down menu not working

My drop down menu was working when I only had one navigation bar, but now that the tutoring pages of my business became sub pages in a website featuring all my businesses, I made the tutoring navigation bar a subnavbar, and at that point, my drop down menus stopped working. When I hover over "services," "contact me," and "resources," I should see a drop down menu, but I don't, so now there are several pages clients can not access. I do not get why they stopped working, and I have tried to research this, but I feel like I have done everything right...
CSS CODE
**/* 1st Navigation Bar */**
#nav {
width: 100%; /* Spans the width of the page */
height: 40px;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(94, 185, 176);
}
.navbar {
height: 40px;
margin: 0;
padding: 0;
border-right: 1px solid #54879d;
}
.navbar li {
height: 50px;
width: 155px;
float: right;
text-align: center;
list-style: none;
margin: 0;
background-color: rgb(94, 185, 176);
font: normal 200%/110% 'chocolatebox deco regular',sans-serif;
font-size: 16px;
}
.navbar a {
padding: 14px 0; /* Adds a padding on the top and bottom so the text appears centered vertically */
border-left: 1px solid #74e3d8; /* Creates a border in a slightly lighter shade of blue than the background. */
border-right: 1px solid #4d9a92; /* Creates a border in a slightly darker shade of blue than the background. */
text-decoration: none; /* Removes the default hyperlink styling. */
color: black;
display: block;
}
.navbar li a:hover {
background-color: #ffe643;
}
.navbar li.active {
background-color: #ffe643;
border-bottom: 5px dashed black;
text-decoration: underline;
}
**/* 2nd Nav bar */**
#subnav {
width: 100%; /* Spans the width of the page */
height: 40px;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ffe643;
}
.subnavbar {
height: 40px;
margin: 0;
padding: 0;
border-right: 1px solid #54879d;
}
.subnavbar li {
height: 50px;
width: 155px;
float: right;
text-align: center;
list-style: none;
margin: 0;
background-color: #ffe643;
font: normal 200%/110% 'chocolatebox deco regular',sans-serif;
font-size: 16px;
}
.subnavbar a {
padding: 14px 0; /* Adds a padding on the top and bottom so the text appears centered vertically */
border-left: 1px solid #fefefb; /* Creates a border in a slightly lighter shade of yellow than the background. */
border-right: 1px solid #fee121; /* Creates a border in a slightly darker shade of yellow than the background. */
text-decoration: none; /* Removes the default hyperlink styling. */
color: black;
display: block;
}
.subnavbar li:hover, a:hover {
background-color: #CFEAE7;
}
.subnavbar li.active {
background-color: #CFEAE7;
**/* Drop down menu */**
.subnavbar li ul {
display: none; /* Hides the drop-down menu */
z-index: 999;
height: 50px;
margin: 0; /* Aligns drop-down box underneath the menu item */
padding: 0; /* Aligns drop-down box underneath the menu item */
background-color: rgb(94, 185, 176);
}
.subnavbar li:hover ul {
display: block; /* Displays the drop-down box when the menu item is hovered over */
}
.subnavbar li ul li a {
border-left: 1px solid #74e3d8;
border-right: 1px solid #74e3d8;
border-top: 1px solid #4d9a92;
border-bottom: 1px solid #4d9a92;
}
.subnavbar li ul li a:hover{
background-color: #ffe643;
}
HTML CODE (This is the code for both nav bars)
<div id="nav">
<ul class="navbar">
<li>Content Writing</li>
<li>Editing</li>
<li>Video Courses</li>
<li class="active">Tutoring</li>
<li><a href=http://tutorwithkatie.org/Blog/blog-2>Blog</a></li>
<li>Home</li>
</ul>
<div id="subnav">
<ul class="subnavbar">
<li></li>
<li>Resources
<ul>
<li>English Resources</li>
<li>Math Resources</li>
<li>Study skills and organization Resources</li>
<li>Parent Resources</li>
</ul>
</li>
<li>Contact Me
<ul>
<li>Request Information</li>
<li>Schedule new client appoitnment</li>
<li>Contact Details</li>
</ul>
</li>
<li>Policies</li>
<li>Current Students
</li>
<li>Services
<ul>
<li>English Tutoring</li>
<li>Homeschool English</li>
<li>Math Tutoring</li>
<li>Online Tutoring</li>
</ul>
</li>
</ul>
<div>
So I have display: none; to hide it and then display: block; to show it on hover, but it no longer displays it on hover. It used to and then the moment I added the first nav bar and called this class .subnavbar, it stopped working....
The reason it isn't working is because you have a lot of issues:
Extra * in your code that are causing CSS issues and are messing up with you CSS. Take all the comment lines out that look like this:
**/* Drop down menu */**
and replace them with a valid comment like this:
/* Drop down menu */
There also is a missing closing } on this CSS rule
.subnavbar li.active {
background-color: #CFEAE7;
and also change this line on the #subnav from overflow: hidden; to overflow: visible; to display the SubNav when you hover over it.
#subnav {
width: 100%; /* Spans the width of the page */
height: 40px;
margin: 0;
padding: 0;
overflow: visible;
background-color: #ffe643;
}
Also a missing closing </div> tag in the HTML for <div id="nav"> and also you have a <div> instead of a closing </div> at the end of the <div id="subnav">.
Here is a working JSFIDDLE for reference where it is working. Hope that clears things up.