drop down navigation menu html5 - css

I am attempting a 2 tier drop down menu. I believe I have everything in place but am not getting the drop down. also the :: after is showing pink in notepad ++. is that correct? Ultimately im trying to achieve 5 horizontal menus with the final actually having a vertical 4 drop down nav menu.
</header>
<nav id="nav_menu">
<ul>
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Get Tickets</li>
<li class="lastitem">About Us
<ul>
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
</nav>
AND THEN THE CSS BELOW. I am confident that the html is correct I believe my trouble is in the CSS..
#nav_menu ul{
list-style-type: none;
position: realative;}
#nav_menu ul li {float: left;}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li{float: none;}
#nav_menu ul li:hover > ul{
display: block; }
#nav_menu > ul::after{
content: "";
display: block;
clear: both;}
#nav_menu ul li a {
text-align: center;
display: block;
width: 160px;
padding: 1em 0;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;}
#nav_menu ul li a.lastitem{border-right:none;}
#nav_menu ul li a.current {color: yellow;}

I did some cleanup in your code and the main problem was the typo in position: relative; on the #nav_menu ul element. Therefore the dropdown was out of the visible screen. See the working example below.
#nav_menu ul{
list-style-type: none;
position: relative;
}
#nav_menu ul li {
float: left;
}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li{
float: none;
}
#nav_menu ul li:hover > ul {
display: block;
}
#nav_menu > ul::after{
content: "";
display: block;
clear: both;
}
#nav_menu ul li a {
text-align: center;
display: block;
width: 160px;
padding: 1em 0;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
}
#nav_menu ul li a.lastitem{
border-right:none;
}
#nav_menu ul li a.current {
color: yellow;
}
<nav id="nav_menu">
<ul>
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Get Tickets</li>
<li class="lastitem">About Us
<ul>
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
</nav>

Related

Dropdown menu do not working correctly

The submenu is not working correctly. It should appears when hover on specific item, but its appearing when hover any item
HTML
<div class="sty">
<ul class="met_clean_list">
<li>Link 01</li>
<ul>
<li><b>Sublink 01</b></li>
<li><b>Sublink 02</b></li>
</ul>
<li>Link 02</li>
<li>Link 03</li>
</ul>
</div>
CSS
.sty {
background:#aaa;
float:left;
width:600px;
}
.sty ul li {
list-style:none;
position:relative;
padding:25px 10px;
float:left;
}
.sty ul ul{
display:none;
}
.met_clean_list:hover ul {
display:block;
background:red;
}
https://jsfiddle.net/59opc6tj/119/
That's because the hover rule you specified doesn't do what you wish it will do.
You have written: If I hover on .met_clean_list, make all uls within it displayed.
What you wanted to write: If I hover on one of the lis, make the following ul visible.
Thus, you should write .met_clean_list li:hover + ul
.sty {
background: #aaa;
float: left;
width: 600px;
}
.sty ul li {
list-style: none;
position: relative;
padding: 25px 10px;
float: left;
}
.sty ul ul {
display: none;
}
.met_clean_list li:hover + ul {
display: block;
background: red;
}
.sty ul ul:hover {
display: block;
}
<div class="sty">
<ul class="met_clean_list">
<li>Link 01</li>
<ul>
<li><b>Sublink 01</b></li>
<li><b>Sublink 02</b></li>
</ul>
<li>Link 02</li>
<li>Link 03</li>
</ul>
</div>
Notice that I also added:
.sty ul ul:hover {
display: block;
}
So the dropdown won't disappear when you hover on it.
I hope this code will be useful for you
Html:
<ul>
<li>Home</li>
<li>Blog</li>
<li class="dropdown">
Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</ul>
css:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
demo:
https://jsfiddle.net/faridvatani/54qypuds/

CSS menu dropdown alignment not working in Chrome

I have been asked to look at this site http://www.edowa.org.au/ but can't find the problem.
The second level menu items are aligned correctly in IE10.0.5 and FF35.0.1 but not in Chrome (latest version). In Chrome the second level menu items are pushed to the right.
Here is the CSS
/* MAIN NAVIGATION - TABS
----------------------------------------- */
#nav {
clear:both;
width: 900px;
height: 29px;
margin: 0 auto;
padding:5px 20px 0 20px;
}
#nav ul {
width: 900px;
display: inline-table;
margin: 0;
padding: 0;
}
#nav li {
list-style: none;
display: table-cell;
text-align: center;
margin: 0;
padding: 0;
}
*:first-child+html #nav li {
float: left;
}
*html #nav li {
float: left;
}
#nav li a {
border: 0;
display: block;
font-weight: bold;
font-size: 14px;
line-height: 29px;
color: #59523f;
text-decoration: none;
}
*:first-child+html #nav li a {
padding:0 33px;
}
#nav li a.current,
#nav li a:hover {
color: #FFFFFF;
background: url(../images/li-bg-hover.jpg) repeat-x;
}
/*_________second level menu__________*/
#nav li ul {
position: absolute;
z-index: 20;
width: 175px;
height: auto;
margin: 0;
padding: 0;
left: -999em;
}
#nav li ul li {
margin: 0;
padding: 0;
width: 175px;
min-height: 31px;
display:block;
}
#nav li:hover ul,
#nav li li:hover ul,
#nav li.sfhover ul,
#nav li li.sfhover ul {
left: auto;
}
*:first-child+html #nav li:hover,
*:first-child+html #nav li li:hover,
*:first-child+html #nav li.sfhover,
*:first-child+html #nav li li.sfhover {
left: auto;
position: static;
}
#nav li ul li a {
padding: 0 10px;
display: block;
width: 175px !important;
line-height: 31px;
height:auto;
font-weight: normal;
font-size: 12px;
text-align: left;
color:#d6d4af;
background: url(../images/li-li-bg.png) repeat-x;
}
#nav li ul li a:hover {
color: #FFFFFF;
background: url(../images/li-li-bg-hover.png) repeat-x;
}
Here is the html
<div id="nav">
<ul>
<li><a href="/" class="current" >Home</a></li>
<li><a href="/meet-the-edo/" class="link" >Who We Are</a></li>
<li><a href="/services/" class="link" >What We Do</a>
<ul>
<li><a href="/services/legal-advice-2/" >Legal Advice</a></li>
</ul>
</li>
<li><a href="/discover/" class="link" >Discover</a>
<ul>
<li><a href="/discover/publications/" >Publications</a></li>
<li><a href="/discover/factsheets/" >Factsheets</a></li>
<li><a href="/discover/newsletters/" >Newsletters</a></li>
<li><a href="/discover/archive/" >Archive</a></li>
<li><a href="/discover/e-bulletins/" >E-Bulletins</a></li>
<li><a href="/discover/community-legal-education/" >Community Legal Education</a></li>
</ul>
</li>
<li><a href="/participate/" class="link" >Participate</a>
<ul>
<li><a href="/participate/join/" >Join</a></li>
<li><a href="/participate/donate/" >Donate</a></li>
<li><a href="/participate/volunteer/" >Volunteer</a></li>
<li><a href="/participate/jobs/" >Jobs</a></li>
</ul>
</li>
<li><a href="/links/" class="link" >Links</a></li>
<li><a href="/contact/" class="link" >Contact</a></li>
Any advice much appreciated.
Try changing your li left: auto; to left: 0; and add position: relative; to #nav li. Like this:
#nav li {
list-style: none;
display: table-cell;
text-align: center;
margin: 0;
padding: 0;
position: relative; /*Added*/
}
#nav li:hover ul,
#nav li li:hover ul,
#nav li.sfhover ul,
#nav li li.sfhover ul {
left: 0; /*Added*/
}
I've created a fiddle here (added colors for testing purposes).
I think it is a little mess within absolute positioning and "auto" value.
Please, try changing the following:
#nav li {
list-style: none;
display: table-cell;
text-align: center;
margin: 0;
padding: 0;
position: relative; /* new line */
}
#nav li:hover ul,
#nav li li:hover ul,
#nav li.sfhover ul,
#nav li li.sfhover ul {
left: 0; /* changed value */
}
It should do it on all major browsers.
#nav{
float : right;
/* or float = left */
}

Highlight Menu on Current Page

I don't understand why the menu won't highlight on current page? on .menu ul li a:hover, .active {color: #788d35} If I put "background-color" instead of "color"it will work. How do I highlight just the text if current page is active?
HTML:
<section class="menu">
<ul>
<li><a class="active" href="home.html"> HOME </a></li>
<li> PORTFOLIO
<ul>
<li> illustrations </li>
<li> portraits </li>
<li> environments </li>
<li> sketches </li>
</ul>
</li>
<li> STORE
<ul>
<li> society6 </li>
<li> redbubble </li>
</ul>
</li>
<li> CONTACT </li>
<li> ABOUT </li>
</ul>
</section>
CSS:
.menu {
height: 29px;
width: 100%;
/*background:orange;*/
}
.menu ul {
width: auto;
list-style-type: none;
font-family: "calibri", "arial";
}
.menu ul li {
position: relative;
display: inline;
float: left;
width: auto;
border-right: 2px solid purple;
margin-left: 10px;
line-height: 12px;
}
.menu ul li:last-child {
border: none;
}
/*removes border after 'about'*/
.menu ul li a {
display: block;
padding: 3px;
color: #854288;
text-decoration: none;
font-size: 20px;
font-weight: strong;
padding-right: 25px;
}
.menu ul li a:hover,
.active {
color: #788d35
/* <-- if I put "background-color" instead of "color" it will work. How do I highlight just the text if current page is active? */
}
.menu ul li ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
position: absolute;
top: 22px;
float: left;
text-align: left;
z-index: 1000;
background-color: white;
}
.menu ul li ul li {
position: relative;
max-width: 140px;
min-width: 140px;
width: 100%;
border: none;
margin-left: -40px;
}
.menu ul li ul li a {
padding: 4px;
margin-left: 1px;
}
Your .active selector is being overruled by the .menu ul li a selector. So you can either change .active selector to .menu ul li a.active or change the color property color: #788d35; to color: #788d35 !important;
See: http://jsfiddle.net/5mpjj/
For more information: http://hungred.com/useful-information/css-priority-order-tips-tricks/

CSS two level menu - second level doesn't appear in proper position

I have the menu using css. The second level menu pops out right one levwl below the actual menu item hover. In the below example, i want the second level appear in line to "Keyboard Entry" menu item. I have attached the html file.
CSS:
#navbar {
margin: 0;
padding: 0;
height: 1.8em;
background-color: #5e8ce9;
}
#navbar li {
list-style: none;
float: left;
}
#navbar li a
{
display: block;
padding: 4px 10px 4px 10px;
background-color: #5e8ce9;
color: #fff;
font-size: 0.85em;
text-decoration: none;
}
#navbar li ul {
display: none;
width: 10em; /* Width to help Opera out */
background-color: #69f;}
#navbar li:hover ul, #navbar li.hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0; }
#navbar li:hover li, #navbar li.hover li {
float: none; }
#navbar li:hover li a, #navbar li.hover li a {
background-color: #69f;
border-bottom: 1px solid #fff;
color: #000; }
#navbar li li a:hover {
background-color: #8db3ff; }
#navbar li:hover ul li:hover ul, #navbar li.hover ul li.hover ul
{
display: block;
position: absolute;
margin-left: 100%;
top:1;
}
#navbar li:hover ul ul, #nav li.sfhover ul ul {
left: -999em;
}
#navbar li:hover ul, #navbar li li:hover ul, #navbar li.sfhover ul, #navbar li li.sfhover ul {
left: auto;
}
MY HTML:
<ul id="navbar">
<li>File
<ul>
<li>Match</li>
<li>View</li>
<li>Exit</li>
</ul>
</li>
<li>Data
<ul>
<li>Import Carbon CSV Files</li>
<li>Rework Carbon Components</li>
<li>Keyboard Entry
<ul>
<li>Orifice Data Entry</li>
<li>Leaflets Data Entry</li>
<li>Rings Data Entry</li>
</ul>
</li>
<li>Specifications</li>
<li>Matched Components</li>
</ul>
</li>
<li>Reports
<ul>
<li>Audit Reports</li>
</ul>
</li>
<li>Admin
<ul>
<li>Security</li>
</ul>
</li>
</ul>
Demo: http://jsbin.com/ewolik/1/edit
Simple dropdown Menu:
http://jsbin.com/ewolik/2/edit
Position the first level of Li elements relative:
#navbar li {
list-style: none;
float: left;
position:relative;
}
Position the second level ul with absolutely with an top offset equal to the first level lis height:
#navbar li:hover ul, #navbar li.hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0;
top:1.8em;
}

Third Tier Sublist in Drop Down Menu Won't Display on Hover

Here's the site I'm working on: http://argumentinamerica.com/
The menu goes like this:
<div id="menu">
<ul id="menu">
<li><span></span>Home</li>
<li class='has-sub'><span></span>Units
<ul>
<li class='has-sub'>Unit 1</li>
<ul>
<li>Read About It</li>
<li>Write About It</li>
<li>Hear About It</li>
<li>Speak About It</li>
<li>Read About It</li>
<li>Write About It</li>
</ul>
<li class='has-sub'>Unit 2</li>
<li class='has-sub'>Unit 3</li>
<li class='has-sub'>Unit 4</li>
<li class='has-sub'>Unit 5</li>
</ul>
<li><span></span>Teacher Center</li>
<li><span></span>About</li>
<li><span></span>Give 1</li>
</ul>
</div>
And the css is like this:
#menu {
margin: 0; padding: 2px 0px 2px 0px;
list-style-type: none;
height: 2.4em;
}
#menu ul, #menu li, #menu span, #menu a {
margin: 0;
padding: 0;
position: relative;
}
#menu li {
float: left;
width: 20%;
}
#menu a {
display: block;
margin: 1px;
height: 2.4em;
font-size: 10px;
line-height: 2.4em;
text-decoration: none;
text-transform: uppercase;
text-align: center;
background: #ffcc66;
color: #996600;
}
#menu span {
position: absolute; top: 8px; left: 8px;
width: 8px; height: 8px;
background: #ff9933;
}
#menu a:hover {
background: #cc3300;
color: #ffcc66;
}
#menu ul{
list-style-type: none;
}
#menu .has-sub {
z-index: 1;
}
#menu .has-sub:hover > ul {
display: list-item;
}
#menu .has-sub ul {
display: none;
position: absolute;
left:0;
}
#menu .has-sub ul li {
*margin-bottom: -1px;
position: relative;
width: 100%;
height: 2.6em;
line-height: 2.4em;
}
#menu .has-sub ul li a {
background: #ff9944;
font-size: 11px;
color: ffcc66;
}
#menu .has-sub ul li:hover a {
background: #ff6633;
color: 993300;
}
#menu .has-sub {
z-index: 1;
}
#menu .has-sub:hover > ul {
display: list-item;
}
#menu .has-sub .has-sub ul {
display: none;
position: absolute;
left:0;
}
#menu .has-sub .has-sub ul {
display: none;
position: absolute;
left:0;
}
#menu .has-sub .has-sub ul li {
*margin-bottom: -1px;
position: relative;
width: 100%;
height: 2.6em;
line-height: 2.4em;
}
#menu .has-sub .has-sub ul li a {
background: #ff9944;
font-size: 11px;
color: ffcc66;
}
#menu .has-sub .has-sub:hover > ul {
display: block;
}
#menu .has-sub .has-sub ul li:hover a {
background: #ff6633;
color: 993300;
}
The third tier is under Units: Unit 1.
I looked at Displaying third tier submenus properly with css only menu and https://stackoverflow.com/questions/13775342/adding-third-tier-to-drop-down-menu and DropDown Menu won't to display on hover and a lot of other questions trying to figure out what's wrong, but I still can't get the third tier to display. I would really appreciate someone taking a look and telling me what I'm missing.
First, the CSS which causes the third tier to appear is not correct:
#menu .has-sub .has-sub:hover > ul {
display: block;
} In this code the '>' targets an ul which is a direct child of a .has-sub:hover element - in your HTML the 3rd tier ul is not a child of the li.has-sub element. You could change the > to a +, which means it targets an ul element directly following the li.has-sub element which for this code causes the third tier to appear. The next problem is that the third tier items appear directly underneath the second tier, so they need to be moved somewhere - see the example code.
http://codepen.io/nztim/pen/GpbqK
Now you need to get the menu to stay visible when you hover over the third tier, but I'll leave that to you, all the best :)

Resources