CSS submenu no longer appearing
This was working and I did something to it, I dont know if it is a code problem or a css problem. Forgive me if the post is not formatted correctly,
this is my first time posting at Stackoverflow.
html
<nav class='navClass'>
<ul>
<li>Home</li>
<li>Things To Do</li>
<ul class="sub-menu">
<li>Shopping</li>
<li>Attractions</li>
<li>Outdoor Fun</li>
</ul>
</li>
<li>Places To Stay</li>
<li>Where to Eat</li>
<li>Contests</li>
<li>History</li>
<li>Events</li>
</ul>
</nav>
css
.navClass > ul{
background-color: #e56109;
color:#ffffff;
margin-top: 0px;
font-size: 20px;
font-family: Arial;
}
.navClass > ul li{
list-style-type: none;
display: inline-block;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 25px;
padding-right: 25px;
position: relative;
}
.navClass > ul li:hover{
background-color: #212121;
position: relative;
}
ul.sub-menu{
position: absolute;
background-color: #e56109;
list-style-type: none;
width: 200px;
margin-left: -25px;
padding-bottom: 0px;
margin-top: 10px;
opacity: 0;
}
ul.sub-menu li{
padding-left: 25px;
padding-top: 5px;
font-size: 15px;
}
ul.sub-menu li:hover{
color: #ffffff;
display: block;
}
.navClass li:hover .sub-menu{
opacity: 1;
}
The sub-menu items need to drop down from the parent item. In this case, the "Things to Do" item.
There is a simple error in your HTML code.
You have closed the <li> tag before.
Use This:
<nav class='navClass'>
<ul>
<li>Home</li>
<li>Things To Do
<ul class="sub-menu">
<li>Shopping</li>
<li>Attractions</li>
<li>Outdoor Fun</li>
</ul>
</li>
<li>Places To Stay</li>
<li>Where to Eat</li>
<li>Contests</li>
<li>History</li>
<li>Events</li>
</ul>
</nav>
.navClass > ul{
background-color: #e56109;
color:#ffffff;
margin-top: 0px;
font-size: 20px;
font-family: Arial;
}
.dropdown {
position: relative;
display: inline-block;
}
.sub-menu {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .sub-menu {
display: block;
background-color: #000000;
cursor: pointer;
}
.navClass > ul li:hover{
background-color: #212121;
position: relative;
}
<nav class='navClass'>
<ul class='t'>
<li class='b'>Home</li>
<span class="dropdown">
<li>Things To Do</li>
<span>
<ul class="sub-menu">
<li>Shopping</li>
<li>Attractions</li>
<li>Outdoor Fun</li>
</ul>
<li>Places To Stay</li>
<li>Where to Eat</li>
<li>Contests</li>
<li>History</li>
<li>Events</li>
</ul>
</nav>
Related
I'm trying to make the drop down menu stay top right with the image behind it if anyone could help would be greatly appreciated i tried using z-index but that didn't work out for me !
( using a img off google so u guys can see what im talking about! )
/* Drop Down Menu */
.navClass {
z-index: 999;
float: right;
}
.right {
float: right;
}
.navClass > ul {
background-color: #5E5D5D;
color: #D8D8D8;
font-size: 20px;
font-family: sans-serif;
}
.navClass > ul > li {
list-style-type: none;
display: inline-block;
padding: 5px 25px;
position: relative;
}
.navClass > ul > li:hover {
background-color: #383838;
}
ul.sub-menu {
position: absolute;
background-color: #383838;
list-style-type: none;
width: 125px;
margin-top: 5px;
padding-left: 0pc;
margin-left: -25px;
padding-top: 5px;
opacity: 0;
}
ul.sub-menu li {
padding-left: 25px;
padding-top: 5px;
padding-bottom: 5px;
}
.navClass li:hover .sub-menu {
opacity: 1;
background-color: #7b7b7b;
}
.navClass ul li a {
text-decoration: none;
color: #D8D8D8;
}
.sub-menu li:hover {
background-color: #383838;
}
/* Background */
/* ZeeFro */
.zeefro {
z-index: -1;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<title>STREAMER // DESIGNER // YOUTUBER</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<nav class="bg-Main">
<img src="">
</nav>
<nav class="zeefro">
<img src="https://i.ytimg.com/vi/d-zKJCKsoWw/maxresdefault.jpg" text-align: center; >
</nav>
<nav class="navClass">
<ul>
<li>Contact Me</li>
<li>Home</li>
<li>About Me</li>
<li><a href="">Portfolio
<ul class="sub-menu">
<li>Logos</li>
<li>Banners</li>
<li>Twitch</li>
<li>Youtube</li>
</ul>
</li>
<li><a href="">Shop
<ul class="sub-menu">
<li>Graphics</li>
<li>Merch</li>
</ul>
</li>
<li><a href="">Social Media
<ul class="sub-menu">
<li>Twitch</li>
<li>Youtube</li>
<li>All</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
Either i did something wrong within the z-index unless i don't know whats happening :P
Kind regards
ZeFrolity
You need to put position: absolute to the div with background.
but
if a image is for background, you will usually want to use css background-image attribute instead of <img> tag.
you will also only need one nav tag only
/* Drop Down Menu */
.navClass {
z-index: 999;
float: right;
}
.right {
float: right;
}
.navClass > ul {
background-color: #5E5D5D;
color: #D8D8D8;
font-size: 20px;
font-family: sans-serif;
}
.navClass > ul > li {
list-style-type: none;
display: inline-block;
padding: 5px 25px;
position: relative;
}
.navClass > ul > li:hover {
background-color: #383838;
}
ul.sub-menu {
position: absolute;
background-color: #383838;
list-style-type: none;
width: 125px;
margin-top: 5px;
padding-left: 0pc;
margin-left: -25px;
padding-top: 5px;
opacity: 0;
}
ul.sub-menu li {
padding-left: 25px;
padding-top: 5px;
padding-bottom: 5px;
}
.navClass li:hover .sub-menu {
opacity: 1;
background-color: #7b7b7b;
}
.navClass ul li a {
text-decoration: none;
color: #D8D8D8;
}
.sub-menu li:hover {
background-color: #383838;
}
/* Background */
/* ZeeFro */
.zeefro {
z-index: -1;
text-align: center;
position: absolute;
width:100%;
height:100%;
background-image: url("https://i.ytimg.com/vi/d-zKJCKsoWw/maxresdefault.jpg")
}
<!DOCTYPE html>
<html>
<head>
<title>STREAMER // DESIGNER // YOUTUBER</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="zeefro">
</div>
<nav class="navClass">
<ul>
<li>Contact Me</li>
<li>Home</li>
<li>About Me</li>
<li><a href="">Portfolio
<ul class="sub-menu">
<li>Logos</li>
<li>Banners</li>
<li>Twitch</li>
<li>Youtube</li>
</ul>
</li>
<li><a href="">Shop
<ul class="sub-menu">
<li>Graphics</li>
<li>Merch</li>
</ul>
</li>
<li><a href="">Social Media
<ul class="sub-menu">
<li>Twitch</li>
<li>Youtube</li>
<li>All</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
You can absolutely position the menu instead. I also removed the margin from body.
/* Drop Down Menu */
body {
margin: 0;
}
.navClass {
position: absolute;
top: 0; right: 0;
}
.right {
float: right;
}
.navClass > ul {
background-color: #5E5D5D;
color: #D8D8D8;
font-size: 20px;
font-family: sans-serif;
}
.navClass > ul > li {
list-style-type: none;
display: inline-block;
padding: 5px 25px;
position: relative;
}
.navClass > ul > li:hover {
background-color: #383838;
}
ul.sub-menu {
position: absolute;
background-color: #383838;
list-style-type: none;
width: 125px;
margin-top: 5px;
padding-left: 0pc;
margin-left: -25px;
padding-top: 5px;
opacity: 0;
}
ul.sub-menu li {
padding-left: 25px;
padding-top: 5px;
padding-bottom: 5px;
}
.navClass li:hover .sub-menu {
opacity: 1;
background-color: #7b7b7b;
}
.navClass ul li a {
text-decoration: none;
color: #D8D8D8;
}
.sub-menu li:hover {
background-color: #383838;
}
/* Background */
/* ZeeFro */
.zeefro {
z-index: -1;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<title>STREAMER // DESIGNER // YOUTUBER</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<nav class="bg-Main">
<img src="">
</nav>
<nav class="zeefro">
<img src="https://i.ytimg.com/vi/d-zKJCKsoWw/maxresdefault.jpg" text-align: center; >
</nav>
<nav class="navClass">
<ul>
<li>Contact Me</li>
<li>Home</li>
<li>About Me</li>
<li><a href="">Portfolio
<ul class="sub-menu">
<li>Logos</li>
<li>Banners</li>
<li>Twitch</li>
<li>Youtube</li>
</ul>
</li>
<li><a href="">Shop
<ul class="sub-menu">
<li>Graphics</li>
<li>Merch</li>
</ul>
</li>
<li><a href="">Social Media
<ul class="sub-menu">
<li>Twitch</li>
<li>Youtube</li>
<li>All</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
I'm having trouble aligning my drop down menu in my nav bar, I've tried every suggestion out there. I've tried left, float: left, right, and pretty much everything else. I think it is possibly something interfering. The drop down menu has everything aligned from center to right of the parent menu item.
https://jsfiddle.net/ethacker/j7tgq95j/3/
My html code:
<header>
<nav>
<h1> Welcome to Mommy Madness</h1>
<ul>
<li class="parentMenu">Home
<ul class="sub-menu">
<li>About</li>
<li>Contact</li>
</ul>
</li>
<li class="parentMenu">Pregnancy
<!--
Gender Predictions:
Old Wive's Tale
Boy vs Girl- The Ramzi Method
-->
<ul class="sub-menu">
<li>Advice</li>
<li>Gender Predictions</li>
<li>Trying To Conceive</li>
</ul>
</li>
<li class="parentMenu">All About Baby
<ul class="sub-menu">
<li>Fetal Development</li>
<li>Guidelines </li>
<li> Milestones</li>
</ul>
</li>
<li class="parentMenu">Party Momma
<!--
Birthdays - Link to 1-10th bdays.
-->
<ul class="sub-menu">
<li>Pregnancy Announcement</li>
<li>Gender Reveal</li>
<li>Baby Shower</li>
<li>Birth Announcement</li>
<li> Birthdays</li>
</ul>
</li>
<li class="parentMenu">Stations
<ul class="sub-menu">
<li>Hospital Bag</li>
<li>Diaper Bag</li>
<li>Changing Station</li>
<li>Baby Gear</li>
</ul>
</li>
<li class="parentMenu">Memory Markers
<!--
Drop Down Menu:
DIY
Purchases
(Both to have holiday/event selectors on right of page)
-->
<ul class="sub-menu">
<li>DIY</li>
<li>Purchases</li>
</ul>
</li>
<li class="parentMenu">Reviews
<ul class="sub-menu">
<li>Games</li>
<li>Gear</li>
<li>Learning</li>
</ul>
</li>
<li class="parentMenu">Blog
<ul class="sub-menu">
<li>Fit Momma</li>
<li>Minimal Momma</li>
<li>Modern Momma</li>
<li>Organic Momma</li>
<li>Organizing Queen</li>
<li>Savings Savvy</li>
<li>Tech Savvy</li>
<li>Traditional Momma</li>
</ul>
</li>
</ul>
</nav>
My css code:
body {
background-color: beige;
color: lightblue;
padding: 0;
margin:0;
}
header {
background-color: lightblue;
padding: 5px 0;
margin: 0;
}
header h1 {
color: cadetblue;
font-family: Arial;
margin: 0;
padding: 5px 15px;
display: inline;
}
.navMenu{
display: inline;
margin: 0;
}
.navMenu .parentMenu {
display: inline-block;
list-style-type: none;
background-color: lightgray;
padding: 5px 10px;
border: thin solid darkgray;
border-radius: 3px;
color: honeydew;
position: relative;
margin: 0;
}
.navMenu .parentMenu a{
color: azure;
}
.navMenu .parentMenu .sub-menu{
display: none;
}
.navMenu .parentMenu:hover .sub-menu{
display: block;
position: absolute;
list-style-type: none;
margin:0;
}
.parentMenu:hover .sub-menu li{
border: thin solid darkgray;
padding: 4%;
background-color: lightgray;
color: honeydew;
text-align: left;
white-space: nowrap;
width: 100%;
list-style-type: none;
margin: 0;
}
.parentMenu .sub-menu li:hover {
background-color: lightsteelblue;
}
.section {
background-color: wheat;
color: darkslategray;
padding: 5px;
float: left;
display: inline;
width: 63%;
margin: 0 1% 1% 1%;
border-radius: 10px;
border: thin solid khaki;
box-shadow: lightgray;
}
#about {
float: right;
width: 30%;
margin: 1% 1% 0 0;
text-align: center;
}
#home{
margin: 1% 0 1% 1%;
}
h4, h3 {
color: lightseagreen;
}
This will align the submenu to the left:
.navMenu .parentMenu .sub-menu {
display: none;
position:absolute;
list-style-type: none;
padding:0;
margin: 0;
left:-1px;
top:27px;
}
.navMenu .parentMenu:hover .sub-menu {
display: block;
}
https://jsfiddle.net/am13qur4/
you did not specify where you want to align your drop down elements. Do you want to align all to the right, center or left. I assumed left so try adding the code below. You may need to adjust the left attribute's value and your hover background styling too.
.sub-menu a{
position: absolute;
left: 3%;
}
Let me know if this helps. Stay warm!
I have a css drop menu that works in all browsers except IE10...works in IE11 and Chrome, etc. I am using Homestead Intuit as the provider.
How can I get the drop down menu to work in IE10 and all versions?
My problem is the hover drop downs work fine in chrome, IE11, but not in IE10. I need the menu to work across all browsers and versions.
One forum I read mentioned that IE doesn't recognize the hover and you have to use java to get around that, but I am not familiar with java or much html coding beyond the basics.
And by not working, I mean that in IE 10, there are no drop downs from the menu at all and the only link that is clickable is the 'Home' and that is because it is not connected to a hover function.
Here is the link to the page... www.LovingHands.net/basketball.html
Here is the head code...
<head>
<style type="text/css">
<!--
body {
margin: 0;
height: 100%;
width: 100%;
font-family: Arial;
font-size: 16px;
}
img {
border-width: 0;
vertical-align: top;
}
.dfltc {
font-family: Impact;
font-size: 20px;
font-weight: normal;
font-style: normal;
text-decoration: none;
text-align: left;
color: #000000;
}
#Oobj21761 {
position: absolute;
font-size: 10px;
z-index: 1;
text-align: left;
left: 8.90em;
top: 13.40em;
width: 71.30em;
height: 4.40em;
}
#Oobj21763 {
position: absolute;
font-size: 10px;
z-index: 2;
text-align: left;
left: 9.10em;
top: 20.10em;
width: 71.10em;
height: 4.60em;
}
/*---- CROSS BROWSER DROPDOWN MENU ----*/
ul#nav {
margin: 0 -200 0 -145px;
}
ul.drop a {
display: block;
color: #fff;
text-decoration: none;
}
ul.drop, ul.drop li, ul.drop ul {
list-style: none;
margin: 0;
padding: 0;
border: 1px solid #000000;
background: #470001;
color: #fff;
}
ul.drop {
position: relative;
z-index: 597;
float: left;
}
ul.drop li {
float: left;
line-height: 1.3em;
vertical-align: middle;
zoom: 1;
padding: 1px 30px;
}
ul.drop li.hover, ul.drop li:hover {
position: relative;
z-index: 599;
cursor: default;
font-size:;
background: #000000;
}
ul.drop ul {
visibility: hidden;
position: absolute;
top: 100%;
left: 0;
z-index: 598;
width: 224px;
background: #FFFFFF;
border: 1px solid #470001;
}
ul.drop ul li {
float: none;
}
ul.drop ul ul {
top: -2px;
left: 100%;
}
ul.drop li:hover > ul {
visibility: visible;
}
-->
</style>
Here is the css menu...
<div id="Oobj21761">
<div id="Gcode17050" class="dfltc">
<ul id="nav" class="drop">
<li>Home</li>
<li>
About
<ul>
<li>About Us</li>
<li>Meet Our Staff</li>
<li>
Endorsements
<ul>
<li>Official / Legal</li>
<li>Pastors / Ministers</li>
<li>Miscellaneous</li>
</ul>
</li>
<li>Our Support</li>
<li>F.A.Q.</li>
</ul>
</li>
<li>
Admission
<ul>
<li>Admission Info</li>
<li>
Endorsements
<ul>
<li>Official / Legal</li>
<li>Pastors / Ministers</li>
<li>Miscellaneous</li>
</ul>
</li>
</ul>
</li>
<li>
Testimonies
<ul>
<li>Individual</li>
<li>Full Service</li>
<li>Schedule Service</li>
<li>Sermons</li>
</ul>
</li>
<li>
Locations
<ul>
<li>Bradenton/Palmetto</li>
<li>Dade City, FL</li>
<li>India</li>
<li>Miami, FL</li>
<li>Jamestown, IN</li>
</ul>
</li>
<li>
Programs
<ul>
<li>Events & Fundraiers</li>
<li>Loving Hands India</li>
<li>Juggalo Outreach</li>
</ul>
</li>
<li>
Contact
<ul>
<li>Contact Us</li>
<li>Prayer Requests</li>
<li>Join Mailing List</li>
<li>Schedule Service</li>
</ul>
</li>
</ul>
</div>
Thanks!
I've been able to create a horizontal menu using (display:inline) and I now have a drop menu thanks to sousMenu. My problem is that all the submenus, regardless of element I hovered over, appear in the same place. How do I work around this?
My menu code thus far:
<ul>
<li>Home</li>
<li class="sousMenu">About Us
<ul>
<li>Board of Directors</li>
</br>
<li>Student Profiles</li>
</br>
<li>Projects</li>
</ul>
</li>
<li class="sousMenu">Get Involved
<ul>
<li>Donations</li>
</br>
<li>Job Board</li>
</br>
<li>Join</li>
</ul>
</li>
<li class="sousMenu">Resources
<ul>
<li>Connections</li>
</br>
<li>Gallery</li>
</br>
<li>Tours</li>
</ul>
</li>
CSS:
#navcontainer ul {
/*margin: 0;*/
margin-left: auto;
margin-right: auto;
padding: 0;
top:180;
right:20;
width:800px;
list-style-type: none;
text-align: center;
position: absolute;
color: #fff;
background-color: #003300;
padding: .2em 1em;
}
#navcontainer ul li {
display: inline;
padding-left:2cm;
}
#navcontainer ul li a {
text-decoration: none;
color: #fff;
background-color: #030;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #000;
}
.sousMenu:hover ul {
display: block;
}
.sousMenu ul {
text-align: center;
display: none;
list-style-type: none;
}
Try setting the parent list item to position: relative and the child ul to position: absolute for starters. I made some other slight modifications to your code to achieve the desired effect.
Here's the CSS:
* {
margin: 0;
padding: 0;
vertical-align: baseline;
}
li {
list-style-type: none;
}
ul.main li {
position: relative;
display: inline-block;
}
.main li:hover > ul {
display: block;
}
ul.sub {
position: absolute;
display: none;
top: 100%;
left: 0;
}
ul.sub li {
display: block;
}
I also cleaned up the HTML a bit. You were missing a closing </ul> tag as well:
<ul class="main">
<li>Home</li>
<li class="sousMenu">About Us
<ul class="sub about">
<li>Board of Directors</li>
<li>Student Profiles</li>
<li>Projects</li>
</ul>
</li>
<li class="sousMenu">Get Involved
<ul class="sub get-involved">
<li>Donations</li>
<li>Job Board</li>
<li>Join</li>
</ul>
</li>
<li class="sousMenu">Resources
<ul class="sub resources">
<li>Connections</li>
<li>Gallery</li>
<li>Tours</li>
</ul>
</li>
</ul>
Here's the fiddle: http://jsfiddle.net/vXhZb/2/
Here is my code so far:
<?php
echo '
<nav class="floatfix">
<ul>
<li>Home</li>
<ul>
<li>£3.99 T-Shirts</li>
<li>£4.99 T-Shirts</li>
</ul>
<li>Log In</li>
<li>Account</li>
<li>Feedback</li>
<li>Checkout</li>
<li>About Us</li>
</ul>
</nav>
';
?>
Here is my CSS
/* =float clearing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
.floatfix {
display: block;
height: 1%;
text-transform: uppercase;
}
.floatfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
How can I get the £3.99 Shirts & £4.99 Shirts as a drop down menu beneath the 'Home' on the navigation bar.
Thankyou very much
Not even going into the CSS you need to enclose the secondary UL in the Home LI like below:
<nav class="floatfix">
<ul>
<li>Home
<ul>
<li>£3.99 T-Shirts</li>
<li>£4.99 T-Shirts</li>
</ul>
</li>
<li>Log In</li>
<li>Account</li>
<li>Feedback</li>
<li>Checkout</li>
<li>About Us</li>
</ul>
</nav>
CSS stolen from a quick tutorial:
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #3b3b3b; }
li:hover li a:hover {
background: #1e7c9a;
}
Demo: http://jsfiddle.net/calder12/7j6H9/
Unless I am missing something, you want to use a select like like so:
<nav class="floatfix">
<ul>
<li>Home</li>
<select id="lstPrice">
<option value="3.99">£3.99 T Shirts</option>
<option value="4.99">£4.99 T Shirts</option>
</select>
<li>Log In</li>
<li>Account</li>
<li>Feedback</li>
<li>Checkout</li>
<li>About Us</li>
</ul>
</nav>