HTML Drop Down Menu navigation doesn't show up - html

I am trying to learn HTML/CSS and during the course I thought of creating a CSS based Drop Down Menu Navigation bar. I read almost all of the tutorials I could find and finally built it, but the problem is it doesn't work as expected, I got the Main menu working but, the lists are not showing up. Here's the structure of my HTML:
<div id="Header"/>
<div id="Navigation" >
<ul id="Menu-H">
<li id="HOME">HOME</li>
<li id="ITEMS">ITEMS</li>
<ul >
<li>New Item</li>
<li>Search Item</li>
</ul>
<li id="Category">CATALOG</li>
<li id="Inventory">INVENTORY</li>
</ul>
<a class="LogOutButton" href="#">LOG OUT</a>
And here is the CSS I built:
#Menu-H {
padding: 0;
margin: 0;
list-style-type: none;
margin-left: 50px;
}
#Menu-H li {
float:left;
}
#Menu-H li:hover {
background: #f4f4f4;
border-radius: 5px 5px 0px 0px;
}
#Menu-H li a {
//border-left: 2px solid blue;
//border-right: 2px solid blue;
//background-color: white;
display:block;
padding: 5px 15px 5px 15px;
text-decoration: none;
text-shadow: 1px 1px 1px #FFFFFF
}
#Menu-H li:hover a {
color: #161616;
text-shadow: 1px 1px 1px#FFFFFF;
}
/* Drop Down Menu.........*/
#Menu-H ul {
background: #161616;
background:rgba(255,255,255,0);
list-style: none;
display: none;
}
Menu-H ul li {
padding-top: 1px;;
float: none;
}
Menu-H li:hover ul {
display:block;
}
#Menu-H li:hover a {
background: #6b0c36;
}
#Menu-H li:hover ul li a:hover {
background: #333;
}
I can not find the reason.

Your HTML is't right, You need to place the secondary <ul> inside the parent <li>
<ul id="Menu-H">
<li id="HOME">HOME</li>
<li id="ITEMS">ITEMS
<ul>
<li>New Item</li>
<li>Search Item</li>
</ul>
</li>
<li id="Category">CATALOG</li>
<li id="Inventory">INVENTORY</li>
</ul>
Also you forgot to add the # in the CSS for two id-s. Here's a fiddle I made where you can see I made some changes that I was talking about and it works:
http://jsfiddle.net/SJQ9B/

Related

My dropdown menu in my nav bar isn't aligning

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!

Gap Between dropdown menu and sub menu

I'd like for the menu sub menu to show 10 pixels underneath the menu, i can achieve that using margin-top on the ul, but then i cant move my mouse down to the sub menu because there is a gap. There are posts very similar to this but i could't extract an answer from them. Like this one
Space between menu and drop down menu
deepMenu {
background: black !important;
margin-left: 100px !important;
position: absolute !important;
}
.lmao li ul {
display: none;
position: absolute;
border-top: 5px solid black;
margin-top: 18px;
}
.lmao li ul li {
display: none;
border-top: 0.1px solid #F2F2F2;
padding: 10px 40px 10px 10px;
margin: 0;
position: relative;
z-index: 9999999;
background: white;
font-size: 8pt;
line-height: 24px;
text-align: left;
}
.lmao li:hover > ul,
.lmao li:hover > ul li {
display: block;
}
<ul class="lmao">
<li class="point1">home
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2 long lel</li>
<li>Sub Menu 3 really bare long mad</li>
<li>Sub Menu 4 dvg</li>
</ul>
<li class="point">features
<ul>
<li>sdfgsdfgsdfgsdfgsdfgsdfg</li>
<li>sdfg</li>
<li>sdfgsdfgsdfgsdfg</li>
<li>sdfgsdfgsdfgsdfgsdfg</li>
</ul>
<li class="point layout">Layouts
<ul>
<li>sfdgsdfgsdfgsdfgsdfgdfgsdgsdf</li>
<li>sfdgsdfgsdfgl</li>
<li>dfsgsdfgsdfgsdfgsdfgsdfgsdfg</li>
<li class="arrow">sfgsdfg
<ul class="deepMenu">
<li>Deep Menu 1
<ul>
<li>Sub Deep 1</li>
<li>Sub Deep 2</li>
<li>Sub Deep 3</li>
<li>Sub Deep 4</li>
</ul>
</li>
<li>Deep Menu 2</li>
</ul>
</li>
</ul>
</li>
<li class="point">pages</li>
<li class="point">light version</li>
</ul>
UPDATE:
Now that you gave the reference, the hover menu is not actually distant from the li itself, but it is positioned right below it. On the example site the li has a height bigger than the text within and has position: relative; on it.
The dropdown is absolute positioned right below this bigger <li> element with a top: 100%; that way it is distant from the text that triggers the dropdown.
Check the updated Snippet bellow with an updated solution.
Margins are not 'hoverable', and therefore the hover selector is not triggered. One way to keep it distant whilst 'hoverable' is to use padding instead of margins.
So you could change your .lmao li ul, although I wouldn't advise adding style to tags as a CSS best practice, I usually adopt a CSS naming convention such as BEM, SMACSS, among others.
/* Reset the ul style */
ul {
list-style: none;
padding: 0;
margin: 0;
}
deepMenu {
background: black !important;
margin-left: 100px !important;
position: absolute !important;
}
.lmao {
width: 100%;
text-align: center;
}
.lmao li {
display: inline-block;
background-color: white;
padding: 15px;
position: relative;
padding: 20px;
}
.lmao li a {
text-decoration: none;
color: black;
}
.lmao li a:hover {
text-decoration: none;
color: #f38763;
}
.lmao li ul {
display: none;
position: absolute;
border-top: 5px solid black;
top: 100%;
min-width: 200px;
}
.lmao li ul li {
display: none;
border-top: 0.1px solid #F2F2F2;
padding: 10px 40px 10px 10px;
margin: 0;
position: relative;
z-index: 9999999;
background: white;
font-size: 8pt;
line-height: 24px;
text-align: left;
}
.lmao li:hover > ul,
.lmao li:hover > ul li {
display: block;
}
<ul class="lmao">
<li class="point1">home
<ul>
<li>Sub Menu 1
</li>
<li>Sub Menu 2 long lel
</li>
<li>Sub Menu 3 really bare long mad
</li>
<li>Sub Menu 4 dvg
</li>
</ul>
<li class="point">features
<ul>
<li>sdfgsdfgsdfgsdfgsdfgsdfg
</li>
<li>sdfg
</li>
<li>sdfgsdfgsdfgsdfg
</li>
<li>sdfgsdfgsdfgsdfgsdfg
</li>
</ul>
<li class="point layout">Layouts
<ul>
<li>sfdgsdfgsdfgsdfgsdfgdfgsdgsdf
</li>
<li>sfdgsdfgsdfgl
</li>
<li>dfsgsdfgsdfgsdfgsdfgsdfgsdfg
</li>
<li class="arrow">sfgsdfg
<ul class="deepMenu">
<li>Deep Menu 1
<ul>
<li>Sub Deep 1
</li>
<li>Sub Deep 2
</li>
<li>Sub Deep 3
</li>
<li>Sub Deep 4
</li>
</ul>
</li>
<li>Deep Menu 2
</li>
</ul>
</li>
</ul>
</li>
<li class="point">pages
</li>
<li class="point">light version
</li>
</ul>
body {
background-color: #cac3bc
}
nav {
float: left;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background-color: #fff;
margin-top: 10px;
padding: 0 20px;
list-style: none;
position: relative;
display: inline-table;
margin-right: -80px;
}
nav ul li {
float: left;
}
nav ul li:hover {
border-bottom: 5px solid #f5aa65;
color: #fff;
}
nav ul li a:hover {
color: #000;
}
nav ul li a {
display: block;
padding: 15px 15px;
font-family: 'PT Sans', sans-serif;
color: #000;
text-decoration: none;
}
nav ul ul {
background-color:#fff;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #000;
}
nav ul ul:before {
content: "";
display: block;
height: 20px;
position: absolute;
top: -20px;
width: 100%;
}
<body>
<nav>
<ul>
<li>One
<ul>
<li>A</li>
<li>B
</ul>
</li>
<li>Two
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</li>
<li>Three
<ul>
<li>A</li>
<li>B</li>
</ul>
</li>
<li>Four</li>
</ul>
</nav>
</body>

How to show all siblings on :hover in pure CSS

Need to select all sibling <li> elements on hover. Tried accepted answer here but it is not working. JSFiddle here
.menu {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;;
background-color: #777;
}
.menu li {
float: none;
display: none;
}
.menu li a {
display: block;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #bbb;
}
.menu li a:hover {
color: #fff;
}
.menu .btn {
display: block;
cursor: pointer;
}
.menu li:hover ~ .menu li{/*ON THIS HOVER NOT SHOWING ALL SIBLIING LIs*/
display: block !important;
}
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
<ul class="menu">
<li class="btn"><a>☰</a></li>
<li>Home</li>
<li>Portfolio</li>
<li>Contact
<ul class="sub-menu">
<li>Sub Menu</li>
<li>Sub Menu</li>
</ul>
</li>
</ul>
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
Your problem is the selector:
.menu li:hover ~ .menu li
A hidden element can't be hovered-over, which means that li:hover is never going to match an element. Also, the general-sibling combinator is trying to find (subsequent) siblings that are <li> elements descending from sibling .menu elements. Which matches no elements in the page.
Converting that to the following selector:
.menu:hover li ~ li
.menu {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
;
background-color: #777;
}
.menu li {
float: none;
display: none;
}
.menu li a {
display: block;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #bbb;
}
.menu li a:hover {
color: #fff;
}
.menu .btn {
display: block;
cursor: pointer;
}
.menu:hover li ~ li {
display: block;
}
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
<ul class="menu">
<li class="btn"><a>☰</a>
</li>
<li>Home
</li>
<li>Portfolio
</li>
<li>Contact
<ul class="sub-menu">
<li>Sub Menu
</li>
<li>Sub Menu
</li>
</ul>
</li>
</ul>
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
works; that said it will - because of the general sibling combinator - match only those <li> elements with a preceding <li> sibling, which means it will, and can, never show the first <li>.
So, instead, I'd suggest using:
.menu:hover li
.menu {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
;
background-color: #777;
}
.menu li {
float: none;
display: none;
}
.menu li a {
display: block;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #bbb;
}
.menu li a:hover {
color: #fff;
}
.menu .btn {
display: block;
cursor: pointer;
}
.menu:hover li {
display: block;
}
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
<ul class="menu">
<li class="btn"><a>☰</a>
</li>
<li>Home
</li>
<li>Portfolio
</li>
<li>Contact
<ul class="sub-menu">
<li>Sub Menu
</li>
<li>Sub Menu
</li>
</ul>
</li>
</ul>
<!--NEED SOLUTION WITHOUT ALTERING HTML -->

CSS display property

I have a horizontal nav bar and my links are lining up diagonally instead of horizontally. There are also bullets showing up by the links too.
Here is my HTML:
<nav id="site" class="body">
<ul>
<li id="meet">Meet the Staff</li>
<li id="conditions">Conditions</li>
<li id="info">Patient Information</li>
<li id="billing">Billing & Insurance</li>
<li id="contact"><a id="right" href="https://painandspinecenter.myezyaccess.com">Contact Us</a></li>
</ul>
My CSS
nav a {
color: #ffffff;
font-size:13px;
list-style:none;
text-decoration:none;
margin: 0 auto;
}
nav li a {
display: block;
float: left;
list-style: none;
height: 44px;
text-align: center;
border-right: 1px solid #fff;
padding-top:10px;
width: 157px;
margin: 0 auto;
text-decoration:none;
}
nav li a#right {
border-right: none;
text-align:top;
}
The website is painandspinecenter.net
any help would be GREATLY APPRECIATED!
I think this is what you wanted. See the fiddle here : http://jsfiddle.net/fyw435h3/
You were missing this from your CSS
nav li{
display: inline;
}
You have some errors that consist in using your A tags as block elements when you should have benn using your LI tags, consider changing your CSS to the following:
#site {
background:#069
}
nav a {
color: #ffffff;
font-size:13px;
list-style:none;
text-decoration:none;
margin: 0 auto;
}
nav li {
display:inline-block;
list-style: none;
height: 44px;
text-align: center;
border-right: 1px solid #fff;
padding-top:10px;
width: 140px;
margin: 0 auto;
text-decoration:none;
}
nav li a#right {
border-right: none;
text-align:top;
}
<nav id="site" class="body">
<ul>
<li id="meet">Meet the Staff
</li>
<li id="conditions">Conditions
</li>
<li id="info">Patient Information
</li>
<li id="billing">Billing & Insurance
</li>
<li id="contact"><a id="right" href="https://painandspinecenter.myezyaccess.com">Contact Us</a>
</li>
</ul>
</nav>

HTML CSS Lists in IE7

I don't normally work with IE7 simply because I hate it, but my latest client uses IE7-IE9 as their default browsers (not very consistent or up-to-date I know). So I have a list that renders fine in all newer browsers and IE8+ but in IE7 the UL seem to merge into the LI. Its like the tag didn't exist and the UL was a part of the LI. Each list item is nested inside of the one on top of it. Its hideous. Anyone know of a hack or a way around this? Is my CSS messed up?
<div class="indentList">
<ul class="level1">
<li class="customer">
Title
</li>
<ul class="level2 level" id="level2">
<li class="site">
Text
</li>
<ul class="level3 level" id="level3">
<li class="engineer indent">
Name
</li>
</ul>
<ul class="level2 level" id="level2">
<li class="site">
Text
</li>
<ul class="level3 level" id="level3">
<li class="engineer indent">
Name
</li>
<ul class="level4 level" id="level4">
<li>
Item
</li>
<li>
Item
</li>
</ul>
</ul>
</ul>
</ul>
</div>
.indentList ul {
margin: 0px;
padding: 0px;
float: left;
}
.indentList li a {
width: 770px;
margin: 0px 0px;
padding: 10px 0px;
display: inline-block;
float: left;
}
.indentList li:hover {
background: #E9E9E9;
}
.indentList li a:hover {
text-decoration: none;
}
.indentList li .edit {
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
padding: 5px 14px;
width: auto !important;
margin: 4px 0px 0px 5px;
text-align: center;
display: inline;
position: relative;
float: right;
}
.indentList li .edit.frozen {
background: #b51a1a url('images/menuBackgroundRed.png') center;
float: right;
}
.indentList li.customer {
background: #787878 url('images/menuBackgroundTaller.png') center;
color: #FFF;
box-shadow: inset 0px 0px 0px;
-moz-box-shadow: inset 0px 0px 0px;
-webkit-box-shadow: inset 0px 0px 0px;
}
.indentList li.customer a {
color: #FFF;
font-family: 'QuicksandBook', Arial, sans-serif;
font-size: 17px;
}
.level2, .level3, .level4 {
display: block;
}
.indentList ul ul ul li {
margin-left: 50px;
width: 840px;
}
.indentList ul ul ul li a {
width: 770px;
}
.indentList ul ul ul ul li {
margin-left: 90px;
width: 800px;
}
.indentList ul ul ul ul li a {
width: 730px;
}
Not your CSS, but your HTML is messed up.
You should be doing this (pseudocode):
<ul class="first-level">
<li>
<ul class="second-level">
<li>
<ul class="third-level">
<li></li>
</ul>
</li>
</ul>
</li>
</ul>
instead of this:
<ul class="first-level">
<li></li>
<ul class="second-level">
<li></li>
<ul class="third-level">
<li></li>
</ul>
</ul>
</ul>