My HTML + CSS drop-down menu does not appear when hovering - html

/* FONTS */
#font-face {
font-family:'MontserratNormal';
src:url(../fonts/montserrat-regular-webfont.eot);
src:url(../fonts/montserrat-regular-webfont.eot#iefix) format("embedded-opentype"),url(../fonts/montserrat-regular-webfont.woff) format("woff"),url(../fonts/montserrat-regular-webfont.ttf) format("truetype"),url(../fonts/montserrat-regular-webfont.svg#MontserratNormal) format("svg");
font-weight:400;
font-style:normal
}
#font-face {
font-family:'MontserratBlack';
src:url(../fonts/montserrat-black-webfont.eot);
src:url(../fonts/montserrat-black-webfont.eot?#iefix) format("embedded-opentype"),url(../fonts/montserrat-black-webfont.woff) format("woff"),url(../fonts/montserrat-black-webfont.ttf) format("truetype"),url(../fonts/montserrat-black-webfont.svg#MontserratBlack) format("svg");
font-weight:900;
font-style:normal
}
#font-face {
font-family:'MontserratBold';
src:url(../fonts/montserrat-bold-webfont.eot);
src:url(../fonts/montserrat-bold-webfont.eot?#iefix) format("embedded-opentype"),url(../fonts/montserrat-bold-webfont.woff) format("woff"),url(../fonts/montserrat-bold-webfont.ttf) format("truetype"),url(../fonts/montserrat-bold-webfont.svg#MontserratBold) format("svg");
font-weight:700;
font-style:normal
}
#font-face {
font-family:"ParentsSuckRegular";
src:url(../fonts/parentssuck.eot);
src:url(../fonts/parentssuck.eot#iefix) format("embedded-opentype"),url(../fonts/parentssuck.woff) format("woff"),url(../fonts/parentssuck.ttf) format("truetype"),url(../fonts/parentssuck.svg) format("svg");
font-weight:700;
font-style:normal
}
/* HEADER */
#logo {
float:left
}
.mainHeader {
clear:both;
color:#000;
background-color:#fff;
height:30px;
padding-bottom:30px
}
.mainNav {
margin:0
}
.mainNav li {
display:inline;
margin-right:50px;
font-family:MontserratBlack;
text-transform:uppercase;
font-size:35px;
color:#BBB;
position:static;
line-height:1.9em
}
#about,#training,#news,#contact,a {
color:#bcbcbc
}
#about:hover,#training:hover,#news:hover,#contact:hover,nav li .current {
color:#13C63E
}
a {
text-decoration:none
}
/* DROP-DOWN MENUS */
.dropdown {
position:relative
}
.drop-nav {
position:absolute;
display:none
}
.drop-nav li {
border-bottom:1px solid rgba(255,255,255,.2)
}
.dropdown:hover > .drop-nav {
display:block
}
.dropdown1 {
position:relative
}
.drop-nav1 {
position:absolute;
display:none
}
.drop-nav1 li {
border-bottom:1px solid rgba(255,255,255,.2)
}
.dropdown1:hover > .drop-nav1 {
display:block
}
<header class="mainHeader">
<ul class="mainNav">
<li>
<a class="current" href="/" id="logo"><img src="images/logo.png"></a>
</li>
<li class="dropdown">
About
<ul class="drop-nav">
<li>
Testimonials
</li>
</ul>
</li>
<li id="news">Services</li>
<li class="dropdown1">
<ul class="drop-nav1">
<li>
The Meltdown
</li>
<li>
Personal Training
</li>
<li>
PIYO / Burn!
</li>
<li>
Little Black Dress
</li>
</ul>
</li>
<li>
Blog
</li>
<li>
Contact Us
</li>
</ul>
</header>
I'm having a bit of trouble with a drop-down menu in my code. I made one based on this. As you can see, the second drop-down menu does not drop. Sorry if this is a simple issue, I started learning HTML and CSS two days ago.
Thanks!

Got it working for you http://jsfiddle.net/b64n0wdn/
Your html was a little bit out of wack, no big deal it happens to the best of us :)
In the you have the first drop down like:
<li class="dropdown">
About
<ul class="drop-nav">
<li>
Testimonials
</li>
</ul>
</li>
In order to make it work I had to put "services" in an anchor uniformly like that previous dropdown, like so:
<li class="dropdown1">
Services
<ul class="drop-nav1">
<li>
The Meltdown
</li>
<li>
Personal Training
</li>
<li>
PIYO / Burn!
</li>
<li>
Little Black Dress
</li>
</ul>
</li>

Related

How to make droppable menu

I have a problem. I can't crate my droppable menu.
https://probapro2.blogspot.com/
I work on Menu 1, but I don't know what to add to make the drop menus to move on right.
<link href='http://fonts.googleapis.com/css?family=Oswald:300,400' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300' rel='stylesheet' type='text/css' />
<div class="nav">
<ul class="menu" id="menu">
<li> home </li>
<li class=""> <a class="drop-ctg" href="#">category</a>
<ul style="overflow: hidden; display: block; height: 0px; z-index: 1072; opacity: 0;">
<li> Category 1 </li>
<li> Category 2 </li>
<li> Category 3 </li>
<li> Category 4 </li>
</ul>
</li>
<li class="">
Menu 1
<ul style="overflow: hidden; display: block; height: 0px; z-index: 1069; opacity: 0;">
<li class="dir">
Menu 2
<ul style="overflow: hidden; display: block; height: 0px; z-index: 1070; opacity: 0;">
<li style="margin-left:50px;"> Menu 3 </li>
<li> Menu 3 </li>
<li> Menu 3 </li>
</ul>
</li>
<li class=" "> Menu 2 </li>
<li> Menu 2 </li>
<li> Menu 2 </li>
</ul>
</li>
<li> Menu 2 </li>
<li> Menu 3 </li>
<li> Menu 4 </li>
<li> 404 Error Page </li>
</ul>
</div>
Here JS fiddle: https://jsfiddle.net/0ugodkb3/2
I want to make Menu 1 to have a droppable menu with menu 2 and on first menu 2, I want to show menu 3.
You can use for that css rule transform with translate value like this:
*{
margin:0;
padding:0;
outline:0;
}
.nav {
width:950px;
height:auto;
border-bottom:1px solid #eee;
margin:10px auto 5px;
display:inline-block;
}
.menu {
width:auto;
list-style:none;
font:$pagenavifont;
text-align:center;
margin:0 auto;
}
.menu a {
float:left;
color:#999;
text-decoration:none;
text-transform:uppercase;
width:auto;
line-height:36px;
padding:0 20px;
}
.menu a:hover,li.menuhover a{
color:#111;
}
.menu li {
position:relative;
float:left;
width:auto;
}
.menu li:last-child {
background:none;
}
.menu ul{
display:none;
position:absolute;
top:36px;
left:0;
background:#fbfbfb;
display:none;
list-style:none;
}
.menu ul li{
float:none;
border-top:1px solid #e3e3e3;
border-right:1px solid #e3e3e3;
border-left:1px solid #e3e3e3;
width:auto;
background:none;
}
.menu ul li:last-child {
border-bottom:1px solid #e3e3e3
}
.menu ul li a{
float:none;
display:block;
background:none;
line-height:36px;
min-width:137px;
width:auto;
text-align:left;
padding-left:10px;
color:#444;
}
.menu ul li a:hover{
background:#fdfdfd;
color:#777;
}
.menu > li > ul {
display: none;
}
.menu > li > ul > li > ul {
transform: translate(100%,0);
display: none;
margin-top: -37px;
}
.menu > li:hover > ul,
.menu > li > ul > li:hover > ul {
display: block;
}
<div class="nav">
<ul class="menu">
<li>
home
</li>
<li class="">
<a class="drop-ctg" href="#">category</a>
<ul>
<li>
Category 1
</li>
<li>
Category 2
</li>
<li>
Category 3
</li>
<li>
Category 4
</li>
</ul>
</li>
<li>
Menu 1
<ul>
<li class="dir">
Menu 2
<ul>
<li>
Menu 3
</li>
<li>
Menu 3
</li>
<li>
Menu 3
</li>
</ul>
</li>
<li>
Menu 2
</li>
<li>
Menu 2
</li>
<li>
Menu 2
</li>
</ul>
</li>
<li>
Menu 2
</li>
<li>
Menu 3
</li>
<li>
Menu 4
</li>
<li>
404 Error Page
</li>
</ul>
</div>
The main thing is to use > selector when defining the display rule for nested menus. This is all what I've added to your css code:
.menu > li > ul {
display: none;
}
/* Position for the 3rd level menu */
.menu > li > ul > li > ul {
transform: translate(100%,0);
display: none;
margin-top: -37px;
}
.menu > li:hover > ul,
.menu > li > ul > li:hover > ul {
display: block;
}
There are a few things that go into making a dropdown menu. It sounds like you're trying to make a dropdown menu that opens up nested menus.
Each pop-out menu will need to:
1) Know the position of the parent that is opening the menu to know where it should be appended.
2) Calculate where the nav should pop up based on where there user is on the browser/screen
You need to append the nav on the right of the menu header you want to open. I'm not sure what your restrictions are but there are vanilla js options:
https://gomakethings.com/how-to-insert-an-element-after-another-one-in-the-dom-with-vanilla-javascript/
that you can use, and also use a mix of position: relative; and position: fixed; to add your nested menus to the right of it's parent.
I would strongly urge you to consider if creating a custom, nested dropdown menu is the right option for you. There are many options out there that have been battle-tested through time. Normally these will also let you style the menu header, and also it's children.
Let me know if you have any more questions :)

How do I stop this <li> from collapsing?

Here yellow is <li> which is child of <ul> at the moment <li> or <ul> don't have float:left or display:inline as soon as I apply either float or display on <li> or <ul>
pink <li> which is child of nested <ul> changes it's appearance to this
<ul class="top_nav">
<li>name
<ul class="sub_nav">
<li>name1 icnkdn ndkcnks kkncksn </li>
<li>name2</li>
<li>name3</li>
</ul>
</li>
<li>home</li>
</ul>
.top_nav{
list-style-type:none;
padding:0;
}
.top_nav > li {
padding:1em 2em;
background:yellow;
position:relative;
}
.sub_nav{
position:absolute;
z-index:1;
background:green;
}
.sub_nav li{
display:block;
background:pink;
padding:1em 3em;
}
https://codepen.io/labeeb/pen/zRxoOR
Your .sub_nav has position: absolute; that's why your <li> element is collapsed. Remove this property and everything will be ok.

Link on the center but icon on the right

I have a problem with position. I want to make the icons on the right align while links are on the center of navigation. But seems like I hit a wall.
This is my HTML
<div id="nav">
<ul>
<li> HOME
</li>
<li> ABOUT
</li>
<li> MUSIC
</li>
<li> GALLERY
</li>
<li> CONTACT
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
<li class="navimage"> <img src="abc.jpg" />
</li>
</ul>
</div>
and this is my CSS
#nav {
border-bottom:2px solid #FFF;
margin-bottom:20px;
padding:0;
text-align:center;
}
#nav li {
display:inline;
}
#nav a {
display:inline-block;
padding:10px;
font-family: Arial, Helvetica, sans-serif;
font-weight:bold;
}
#nav a:hover {
color:#DEB887;
}
.navimage img {
width:30px;
height:30px;
border-radius:50%;
-webkit-border-radius:50%;
-moz-border-radius:50%;
-ms-border-radius:50%;
-o-border-radius:50%;
}
.navimage img a {
text-align:right;
}
here is the jsfiddle to check.
http://jsfiddle.net/zN92c/
Replace:
.navimage img a {
text-align:right;
}
With:
.navimage {
float:right;
}
According to your css
.navimage img a
is being aligned right. But the list item itself has no position, Try floating it to the right using:
.navimage { float: right; }
That would alight the list item to the right.

Add submenu to existing menu

Hi I have a basic menu for which I would like to add a submenu, that appears only when a certain menu link is hovered. Everything I have tried does not hide the submenu when a link is not hovered. Here is my code:
CSS
.navmenu{
float:right;
font-size: 13px;
font-weight:400;
text-transform: uppercase;
}
.navmenu li{
position: relative;
display: inline-block;
float: left;
}
.navmenu li a{
text-decoration:none;
color:#eee;
padding:15px 37px 19px 37px;
}
.navmenu li a:hover{
background:#36332e;
}
.active a{
background:#36332e;
}
HTML
<ul class="navmenu">
<li class="active">Home</li>
<li>About Us
<ul>
<li>Sub Link 1</li>
<li>SubLink 2</li>
</ul>
</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact Us</li>
</ul>
You need to initially hide the menu:
.navmenu li ul { display: none; }
and then display it when you hover over the nav item:
.navmenu li:hover ul { display: none; }
You should also be careful about defining styles that target .navmenu li or .navmenu li a because those will also target your submenu. You should instead use child selectors, giving you more control over the non-submenu links, so your selectors will look like:
.navmenu > li
.navmenu > li > a
I've encorperated some of those changes into this JSFiddle to get you started:
http://jsfiddle.net/Wexcode/B5P26/
Edit:
This is actually going to lose it's hover state when you hover over the submenu links:
.navmenu > li > a:hover {
background:#36332e;
}
Instead, you should do this:
.navmenu ul { position: absolute; }
.navmenu > li:hover { background: #e6332e; }
.navmenu > li > a { display: block; }
Since the <ul> is nested inside the <li> element, you won't lose the hover state when you hover over the submenu links. I updated the fiddle to reflect these changes.
<ul class="navmenu">
<li class="active">Home</li>
<li>About Us
<ul>
<li>
Sub Link 1
<ul>
</li> <a href=# >hi hi hi</a>
<ul>
<li>hello hello hello</li>
<li>hello hello hello</li>
<li>hello hello hello</li>
</ul>
</li>
</li><a href=# >hi hi hi</a> </li>
</li> <a href=# >hi hi hi</a> </li>
</ul>
</li>
<li>SubLink 2</li>
</ul>
</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact Us</li>
</ul>

How to fix CSS menu bug

I have a CSS3 Menu. When a menu items text is too long the design breaks. I want the text to simply move up to fit
the text. For example: At www.casa.gov.au the menu item text REGULATIONS AND POLICY starts higher than the rest
of the items. This prevents the menu width and height changing to fit the larger text.
How would I go about doing this with the menu attached in the JS FIDDLE: http://jsfiddle.net/UU4rm/
The problem is associated with the line height at #css li a { }
CSS CODE
/* MENU */
#cssmenu {
border:none;
border:0px;
margin:0px;
padding:0px;
font-size:12px;
font-weight:bold;
border-bottom: solid 1px rgb(77,77,77);
}
#cssmenu ul {
background:#333333;
height:39px;
list-style:none;
margin:0;
padding:0;
display: table;
width: 100%;
}
#cssmenu li {
padding:0px;
display: table-cell;
width: 115px;
}
#cssmenu li a {
background:#333333 url('../images/seperator.gif') bottom right no-repeat;
color:#FFF;
display:block;
font-weight:normal;
line-height:39px;
margin:0px;
padding:0px 0px;
text-align:center;
text-decoration:none;
width: 115px;
}
#cssmenu li a:hover,
#cssmenu ul li:hover a,
#cssmenu li a:focus,
#cssmenu ul li:focus a{
background: #2580a2;
color:#FFFFFF;
text-decoration:none;
float: none;
}
#cssmenu li ul {
background:#333333;
display:none;
height:auto;
padding:0px;
margin:0px;
border:0px;
position:absolute;
width:230px;
z-index:200;
/*top:1em;
/*left:0;*/
}
#cssmenu li.force-show ul,
#cssmenu li:hover ul,
#cssmenu li a:focus + ul{
display:block;
}
#cssmenu li li {
background:url('../images/sub_sep.gif') bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:230px;
}
#cssmenu li:hover li a,
#cssmenu li:focus li a {
background:none;
}
#cssmenu li ul a {
display:block;
height:35px;
font-size:11px;
font-style:normal;
margin:0px;
padding:0px 10px 0px 15px;
text-align:left;
width: 205px;
}
#cssmenu li ul a:hover,
#cssmenu li ul li:hover a,
#cssmenu li ul a:focus,
#cssmenu li ul li:focus a{
background:#2580a2 url('../images/hover_sub.gif') center left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
width: 205px;
}
#cssmenu p {
clear:left;
}
:focus {
outline:none;
}
::-moz-focus-inner {
border:0;
}
HTML CODE
<div id="cssmenu"> <ul> <li>Home</li>
<li class="has-sub"> Operations <ul>
<li>Individuals
</li>
<li>Aircraft owners
</li>
<li>Aircraft operators
</li>
<li>Flight training
</li>
<li>Aerodromes
</li>
<li>Office of airspace regulation
</li>
<li>Sport aviation
</li>
<li>Class D
</li>
<li>Non-towered aerodromes
</li>
<li>Dangerous goods
</li>
<li>Ground operations
</li>
<li>Non-compliance notice
</li>
<li>Unmanned Aircraft Systems (UAS)
</li>
<li>General Aviation (GA) task force
</li>
<li>Regional Aviation Safety Forum (RASF)
</li>
<li>Drug and Alcohol Management Plans
</li>
</ul></li>
<li class="has-sub"> Airworthiness <ul>
<li>Maintenance regulations
</li>
<li>Personnel
</li>
<li>Certification and design
</li>
<li>Manufacturing
</li>
<li>Continuing airworthiness
</li>
<li>Airworthiness directives
</li>
<li>Maintenance organisations
</li>
<li>Flight test and evaluation
</li>
</ul></li>
<li class="has-sub"> Regulations & Policy <ul>
<li>Current rules
</li>
<li>Changing the rules
</li>
<li>Enforcement action
</li>
<li>Policy notices
</li>
<li>Australia's state safety program
</li>
<li>Performance based navigation (PBN)
</li>
<li>Licensing regulations
</li>
</ul></li>
<li class="has-sub"> Manuals & forms <ul>
<li>Manuals
</li>
<li>Forms
</li>
<li>CASA online store
</li>
<li>Temporary Management Instructions (TMIs)
</li>
</ul></li>
<li class="has-sub"> Education <ul>
<li>AviationWorx
</li>
<li>eLearning catalogue
</li>
<li>Flight Safety Australia
</li>
<li> Pilot guides and information
</li>
<li>OnTrack
</li>
<li>Human factors
</li>
<li>Safety management systems
</li>
<li>Seminars and workshops
</li>
<li>Aviation safety advisers
</li>
<li>Advice for air travellers
</li>
<li>CASA online store
</li>
<li>Out-n-Back
</li>
</ul></li>
<li class="has-sub"> Services <ul>
<li>Licences & registrations
</li>
<li>Self Service Portal
</li>
<li>Service standards & fees
</li>
<li>Permission application centre (PAC)
</li>
<li>Aviation medicals
</li>
<li>Delegates and authorised persons
</li>
</ul></li>
<li class="has-sub"> About CASA <ul>
<li>Contact CASA
</li>
<li>CASA board
</li>
<li>CASA's Director
</li>
<li>Recent media releases
</li>
<li>Corporate publications
</li>
<li>CASA on Twitter
</li>
<li>Corporate policy
</li>
<li>Careers at CASA
</li>
<li>Research and statistics
</li>
</ul></li>
</ul>
</div>
It looks to me (in FF), that it's the bottom border attribute that's causing a goofy black line under your menu.
#cssmenu {
border-bottom: solid 1px rgb(77,77,77);
}
Eliminating that bottom border attribute, and adding addition text to the menu items (causing a wrap/second line) acted as expected.