Subnavbar drop down menu not working - html

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.

Related

Nav bar padding and margins not reacting as expected

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>

border-bottom dropping entire div

Alright so the problem is this, when I hover over the li:a my entire div will drop down a bit and then come back once I finish hovering. Im just trying to set it so it will just show the border-bottom without dropping the entire div a bit down
<div id="header_left">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
and the css configuration is
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
border-bottom: 2px solid green;
}
just add a transparent border to the none hovered state of your element.
like this:
li a {
border-bottom: 2px solid transparent;
}
this will help getting rid of the bumpiness on hover.
If you are trying to get the individual menu item hovered on to show the border at the bottom then you might want to set an ID for each menu item and specify what it does in css on hover. As it is right you are targeting everything which is why the whole thing drops on hover. Its an easy fix, just needs a few more lines of code.
Always adds "box-sizing: border-box" to include borders and padding inside box model
Set default transparent border and change only the color on hover
* {
box-sizing: border-box;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-bottom: 2px solid transparent;
}
li a:hover {
border-color: green;
}
<div id="header_left">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>

code work in jsfiddle but not work in my html page

i try to edit my code in jsfiddle until it works properly and at last it works properly in jsfiddle and output is same as want i want but when i try this same code in my abc.html page and also css then code does not work whether this work in jsfiddle
HERE SIS JSFIDDLE IMAGE WITH CODE AND OUTPUT
AND HERE IS MY CODE AND HTML
.wrap {
width: 100%;
/* Spans the width of the page */
height: 40px;
margin: 0;
/* Ensures there is no space between sides of the screen and the menu */
z-index: 99;
/* Makes sure that your menu remains on top of other page elements */
position: relative;
background-color: #366b82;
}
.navbar {
height: 50px;
padding: 15px;
margin: 0;
position: absolute;
/* Ensures that the menu doesn’t affect other elements */
border-right: 1px solid #54879d;
margin-left: 55px;
padding-left: 15px;
padding-bottom: 15px;
padding-top: 0px;
margin-left: 25px;
}
.navbar li {
height: auto;
width: 131px;
/* Each menu item is 150px wide */
float: left;
/* This lines up the menu items horizontally */
text-align: center;
/* All text is placed in the center of the box */
list-style: none;
/* Removes the default styling (bullets) for the list */
font: normal bold 12px/1.2em Arial, Verdana, Helvetica;
padding: 0;
margin: 0;
background-color: #366b82;
}
.navbar a {
padding: 18px 0;
/* Adds a padding on the top and bottom so the text appears centered vertically */
border-left: 1px solid #54879d;
/* Creates a border in a slightly lighter shade of blue than the background. Combined with the right border, this creates a nice effect. */
border-right: 1px solid #1f5065;
/* Creates a border in a slightly darker shade of blue than the background. Combined with the left border, this creates a nice effect. */
text-decoration: none;
/* Removes the default hyperlink styling. */
color: white;
/* Text color is white */
display: block;
}
.navbar li:hover,
a:hover {
background-color: #54879d;
}
.navbar li ul {
display: none;
/* Hides the drop-down menu */
height: auto;
margin: 0;
/* Aligns drop-down box underneath the menu item */
padding: 0;
/* Aligns drop-down box underneath the menu item */
}
.navbar li:hover ul {
display: block;
/* Displays the drop-down box when the menu item is hovered over */
}
.navbar li ul li {
background-color: #54879d;
}
.navbar li ul li a {
border-left: 1px solid #1f5065;
border-right: 1px solid #1f5065;
border-top: 1px solid #74a3b7;
border-bottom: 1px solid #1f5065;
}
.navbar li ul li a:hover {
background-color: #366b82;
}
/* i add this css code for link box*/
.navbar li ul li ul li {
display: block;
}
.b:hover .a {
display: block;
margin-left: 130px;
margin-top: -50px;
}
.a {
display: none;
}
<div id="menu">
<div id="wrap">
<ul class="navbar">
<li>HOME
</li>
<li>ABOUT US
<ul id="Ul1">
<li><a id="A1" href="Company_Profile.html">Company Profile</a>
</li>
<li>Our Philsohpy
</li>
<li>CEO Profile
</li>
<li>Board of Directors
</li>
<li>Our People
</li>
<li>Global Partnership
</li>
<li>Career
</li>
</ul>
</li>
<li>TRAINING
<ul id="Ul2">
<li><a id="A2" href="Academics.html">Academics</a>
</li>
<li>Corporate
</li>
<li>Our Personnel
</li>
</ul>
</li>
<li>PUBLISHING
</li>
<li>CONFERENCES
</li>
<li>EXHIBITION
</li>
<li>RESEARCH
<ul id="subnavlist">
<li><a id="subcurrent" href="About_gjbssr.html">About GJBSSR</a>
</li>
<ul class="c">
<li class="a"> Link
</li>
</ul>
<li>Data Collection Services
</li>
<li>Editing & Proof Reading
</li>
</ul>
</li>
<li id="active">CONTACT US
</li>
</ul>
</div>
</div>
and output is
I managed to cure a similar problem by right clicking the result window of jsfiddle and choosing "View Frame Source". Then simply copying and pasting into a new html document. Hope this helps.
I am not sure what went wrong for you. I used the same code to see if it works and it worked for me. In case you are new to HTML and CSS, you need to have a starting and closing tags for html and body. Also a head tag to link your CSS file to it.
<html>
<head>
<style>
<!-- your CSS here -->
</style>
</head>
<body>
<!-- your HTML here -->
</body>
</html>

another box in menu bar html css

i try to create box e.g link box.. so when i hover mouse on research then menu appears e.g about gjbssr,data collection services etc... but link always appear with this menu and i want when i hover mouse on about gjbssr then link box will be appear
image
code
.navbar {
height: 50px;
padding: 15px;
margin: 0;
position: absolute; /* Ensures that the menu doesn’t affect other elements */
border-right: 1px solid #54879d;
margin-left: 55px;
padding-left:15px;
padding-bottom:15px;
padding-top:0px;
margin-left:25px;
}
.navbar li {
height: auto;
width: 131px; /* Each menu item is 150px wide */
float: left; /* This lines up the menu items horizontally */
text-align: center; /* All text is placed in the center of the box */
list-style: none; /* Removes the default styling (bullets) for the list */
font: normal bold 12px/1.2em Arial, Verdana, Helvetica;
padding: 0;
margin: 0;
background-color: #366b82;
}
.navbar a {
padding: 18px 0; /* Adds a padding on the top and bottom so the text appears centered vertically */
border-left: 1px solid #54879d; /* Creates a border in a slightly lighter shade of blue than the background. Combined with the right border, this creates a nice effect. */
border-right: 1px solid #1f5065; /* Creates a border in a slightly darker shade of blue than the background. Combined with the left border, this creates a nice effect. */
text-decoration: none; /* Removes the default hyperlink styling. */
color: white; /* Text color is white */
display: block;
}
.navbar li:hover, a:hover {background-color: #54879d;}
.navbar li ul {
display: none; /* Hides the drop-down menu */
height: auto;
margin: 0; /* Aligns drop-down box underneath the menu item */
padding: 0; /* Aligns drop-down box underneath the menu item */
}
.navbar li:hover ul {
display: block; /* Displays the drop-down box when the menu item is hovered over */
}
.navbar li ul li {background-color: #54879d;}
.navbar li ul li a {
border-left: 1px solid #1f5065;
border-right: 1px solid #1f5065;
border-top: 1px solid #74a3b7;
border-bottom: 1px solid #1f5065;
}
.navbar li ul li a:hover {background-color: #366b82;}
// i add this css code for link box
.navbar li ul li ul li
{
margin-top:-50px;
margin-left:130px;
display:block;
}
html
<div id="wrap">
<ul class="navbar">
<li>RESEARCH
<ul id="subnavlist">
<li><a id="subcurrent" href="About_gjbssr.html">About GJBSSR</a>
<ul>
<li> <a href="#" >Link</a></li>
</ul></li>
<li>Data Collection Services</li>
<li>Editing & Proof Reading</li>
</ul>
</li>
<li id="active">CONTACT US</li>
</ul>
</div>
any one tell me please?
Try this http://jsfiddle.net/94bws6ab/2/
HTML
<div id="content">
<ul class="a">
<li class="a_a">About
<ul class="b">
<li class="b_b">BOX</li>
</ul>
</li>
</ul>
</div>
CSS
ul{
list-style:none;
}
.b{
display:none;
}
.a_a:hover .b{
margin-top:-15px;
margin-left:20px;
display:block;
}
EDIT OLD
http://jsfiddle.net/h0b8h1ek/
EDIT
Didn't notice it till now, your code went wrong because you used // to begin a comment in css /* is used this is the part that i changed
/*i add this css code for link box*/
That seemed to solve your problem here is the link to the fiddle http://jsfiddle.net/h0b8h1ek/1/

How do I display the bottom border of parent instead of top border of child?

Here is what I have - http://jsfiddle.net/SQApr/
CSS
/*
** MainNav is the div containing the navigation information
** This is defining overall size and shape
*/
#mainNav {
clear: both;
min-height: 40px;
width: 100%;
font-size: 18px;
position: relative;
}
/*
** Main list padding and style
*/
#mainNav ul {
padding: 0;
margin: 0 auto;
list-style: none;
}
/*
** Expand nav list for new information
*/
#mainNav ul:hover {height: 240px;}
/*
** Main item size and position
*/
#mainNav li {
float: left;
width: 19.805%;
height: 40px;
border-left: 1px solid #E8DEA5; /*******************************************/
border-right: 1px solid #E8DEA5; /* Make the border exist for sizing issues */
border-top: 1px solid #E8DEA5; /*******************************************/
}
/*
** Main item on hover
*/
#mainNav li:hover {
background-color: #ffffff; /* White */
border-left: 1px solid green;
border-right: 1px solid green;
border-top: 1px solid green;
border-bottom: 1px solid white;
}
/*
** Main item link formatting
*/
#mainNav li a {
margin: 0;
display: block;
line-height: 40px;
text-align: center;
text-decoration: none;
color: #000000; /* Black */
}
/*
** Main div position and bg color on list item hover
*/
#mainNav li:hover .mainDiv {
position: absolute;
left: 0;
background-color: #ffffff; /* White */
}
/*
** Any div within mainNav's li must have position relative
*/
#mainNav li div {
position: relative;
padding: 0;
margin: 0;
}
/*
** Main div position
*/
#mainNav li .mainDiv {
width: 1024px; /* Same as #wrapper in styles.css */
height: 200px;
left: -9999px;
border: 1px green solid;
}
#mainNav li .title {
clear: both;
position: relative;
top: 30px;
left: 50px;
font-size: 24px;
font-weight: bold;
color: #0b5a5a; /* Gray blue */
border-bottom: 2px solid #0b5a5a; /* Gray blue */
}
.navLinks li {
float: left;
display: block;
border: none;
}
HTML
<div style="width:1024px;">
<div id="mainNav">
<ul>
<li>Home
<div class="mainDiv">
<span class="title">Welcome to the website!</span>
<div style="border:red 1px solid;
top: 60px;
left: 60px;
width: 400px;
height: 80px;">
Here will be a paragraph filled with more information about what the site does
and how it will benefit the community and companies. Or anything else you
would like to say on every page.
</div>
<div style="border:red 1px solid;
clear: both;
top: -60px;
left: 600px;
width: 200px;
height: 80px;">
<ul class="navLinks">
<li>item 1</li>
<li>item 2</li>
<li>Third link</li>
</ul>
</div>
</div>
</li>
<li>Community
<div class="mainDiv">
<span class="title">Community</span>
Browse People & Companies</br>
Directory</br>
Make Your Voice Heard</br>
Forums
</div>
</li>
<li>Information
<div class="mainDiv">
<span class="title">Information</span>
First link</br>
List within a list
First link</a></br>
Second link</a></br>
Section Title</br>
Third link
</br>
Third link
</div>
</li>
<li>Business Opportunities
<div class="mainDiv">
<span class="title">Business Opportunities</span>
First link</br>
Second link</br>
Third link
</div>
</li>
<li>Support
<div class="mainDiv">
<span class="title">Support</span>
FAQs</br>
Site Map</br>
Third link
</div>
</li>
</ul>
</div>
</div>
When ever you roll over the list items to display the hidden div they contain, the top border of the div overlaps the bottom border of the list item. I need to reverse this to make it look like the list item opens up into the div.
Any ideas?
give the div that opens up a z-index: -1
like here: http://jsfiddle.net/SQApr/3/
You can use the z-index property to put the nav over the mainDiv, giving the mainDiv a lower value than the nav.
z-index at W3Schools
Change li:hover a - add white bottom border, make its position relative to add z-index
See: http://jsfiddle.net/SQApr/1/
By the way: I also had to add negative margin to li:hover .mainDiv
Edit:
Chanckjh version is much simpler than mine.