I made a navigation bar on top of the screen. If I'm on a specific page, let's say "Contact", I want the word be highlighted. If I switch to "Home", the word "Home" is highlighted, and so on. I am only allowed to use CSS and HTML.
body {
background: black;
}
nav {
padding:0;
right:1vw;
margin: 0 0 0px 0;
position: fixed;
top: 0vh;
text-align:center;
background-color:rgba(255, 255, 255, 0.4);
width:98%;
-moz-border-radius: 15px;
border-radius: 15px;
}
nav li {
top:2vh;
font-family:Verdana, Geneva, sans-serif;
font-size: 13pt;
display: inline-block;
margin-left:2vw;
margin-right:2vw;
margin-bottom:2vh;
margin-top:2vh;
}
nav li a {
white-space: nowrap;
display: block;
text-decoration: none;
text-transform: uppercase;
text-shadow: 1px 1px 2px rgba(71, 80, 23, 0.3);
color: #fff;
padding: 0;
letter-spacing: 1px;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
text-align:center;
}
nav:hover li a {
}
nav li a:hover {
background: transparent;
text-shadow: 0px 0px 20px #cc9900;
color: #ffff99;
}
<nav>
<li>Home</li>
<li>De dump</li>
<li>Opdrachten</li>
<li>Groepsopdracht</li>
<li>Over mij</li>
<li>Contact</li>
</nav>
Use following code .
Change it accordingly
a:link, a:visited {
display: block;
width: 175px;
font-weight: bold;
color: #FFFFFF;
background-color: #00BFFF;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
}
a:hover, a:active {
background-color: #0066FF;
}
You can add a class for the <li>, say for eg <li class="active">Home</li> if you are in the home page.
Similarly, if you are in De Dump page, then the <li> should be like
<li class="active">De dump</li>
After you do this, you can just style the class in CSS like
.active{
color:red;
}
you can simply style the relevant list item on each of your pages, for example on the page "Opdrachten" just style the corresponding list item by default:
nav li:nth-child(3) a{
background:yellow;
box-shadow:0 0 4px red;
border-radius:4px;
}
<nav>
<li>Home</li>
<li>De dump</li>
<li>Opdrachten</li>
<li>Groepsopdracht</li>
<li>Over mij</li>
<li>Contact</li>
</nav>
CSS
nav ul li {
background-color: #000000;
}
#page1 ul li.page1 {
background-color: #FFFFFF;
}
#page2 ul li.page2 {
background-color: #FFFFFF;
}
#page3 ul li.page3 {
background-color: #FFFFFF;
}
Page 1 HTML
<nav id="page1">
<ul>
<li class="page1">Page 1</li>
<li class="page2">Page 2</li>
<li class="page3">Page 3</li>
</ul>
</nav>
Page 2 HTML
<nav id="page2">
<ul>
<li class="page1">Page 1</li>
<li class="page2">Page 2</li>
<li class="page3">Page 3</li>
</ul>
</nav>
Change nav id to = page3 for page 3
Related
I'm having a little problem, I was trying to make a menu combining items with image and other items with labels, as in the attached image, but it doesn''t work.
Next image shows how it is currently. With error.
I've tried with this code, but my "picture item" don't stand next to the "label item":
.sprite-icons {
background: url(../images/icons/sprite-icons_menu.png) no-repeat top left;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
width: 33px; height: 30px;
}
.sprite-icons.icon_home {
background-position: 0px 0px;
}
.icon_home:hover{
background-position: -48px 0px;
}
.sprite-icons.icon_home_active {
background-position: -48px 0px;
}
.sf-menu{
border-bottom: 1px solid black;
list-style-type:none;
line-height: 1.0;
text-align: center;
padding: 10px 10px 8px 10px;
float: left;
width: 99%;
}
.sf-menu a{
text-decoration: none;
color: #606060;
-webkit-transition: all 0.3s ease; -o-transition: all 0.3s ease; -moz-transition: all 0.3s ease;
}
.sf-menu a:hover{
color: #ffffff;
background-color: #ee1c24;
padding: 10px 6px 6px 6px;
}
.sf-menu li{
display: inline;
padding: 20px;
}
<nav>
<ul class="sf-menu">
<li><a href="" title="Home">
<div class="sprite-icons icon_home">
</div></a>
</li>
<li>A EMPRESA</li>
<li>SERVIÇOS</li>
<li>SISTEMA</li>
<li>TRABALHE CONOSCO</li>
<li>CONTATO</li>
</ul>
</nav>
How can I solve this?
Better solution should be use pseudo-element
:before
Example:
ul li
{
display: inline-block;
}
.icon-tutti:before {
content: "\e908";
}
span [class^=icon-] {
font-size: 1.3em;
margin-right: 10px;
color: #ff653e;
}
<ul>
<li><span class="icon-tutti"></span></li>
<li>Second Element</li>
<li>Third Element</li>
</ul>
You can also use an image url as content, but using icons should be better. Try fontAwesome for example.
I saw already some solutions, but i can't figure out how can i put some of these solutions in my code, or some solutions uses something that i can't use in my project.
Let's go to the question:
I need to make an already existing CSS drop-down menu accessible for keyboard navigation. I got some progress in opening the drop-down menu with [Tab] but i can't navigate into the options inside.
Here is my code:
.menu .options-menu-dropdown{
display: inline-block;
font-family: 'OpenSans Bold';
font-size: 16px;
color: #646464;
text-decoration: none;
cursor: pointer;
position: relative;
}
.menu .menu-dropdown{
z-index: -1;
visibility: hidden;
opacity: 0;
position: absolute;
top: 0;
right: 0;
min-width: 180px;
text-align: right;
overflow: hidden;
margin-top: -6px;
margin-right: -6px;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
}
.menu .options-menu-dropdown:focus .menu-dropdown,
.menu .options-menu-dropdown:hover .menu-dropdown{
z-index: 100;
visibility: visible;
opacity: 1;
}
.menu .title-dropdown{
background-color: #005e8b;
font-size: 16px;
padding: 8px 6px;
white-space: nowrap;
border-bottom: 1px solid #b4b4b4;
color: #FFF;
}
.menu .menu-dropdown-item{
display: block;
background-color: white;
padding: 12px 32px 12px 12px;
text-decoration: none;
cursor: pointer;
font-size: 16px;
color: #323232;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
border-top: #b4b4b4 1px solid;
border-left: #b4b4b4 1px solid;
border-right: #b4b4b4 1px solid;
}
.menu .menu-dropdown-item:last-child{
border-bottom: #b4b4b4 1px solid;
}
.menu .menu-dropdown-item:focus,
.menu .menu-dropdown-item:hover{
background-color: #b4b4b4;
color: #fff;
}
<div class="menu" align="center" >
<div class="options-menu-dropdown" tabindex="0">
<div>Test Menu</div>
<div class="menu-dropdown">
<div class="title-dropdown">Opened Test Menu</div>
Menu Item 1
Menu Item 2
Menu Item 3
</div>
</div>
</div>
code http://codepen.io/WillCodebit/pen/XpaqqJ
Note: I'm trying to avoid any javascript solution, because in this project I need to use GWT for any javascript, it is a pattern that I can't violate.
Thanks in advance.
EDIT
This menu should have a similar behavior than the account menu of Google. And the options inside must be accessible by keyboard too.
I had the exact same question – but did find my answer scattered over different places on the internet which is why I post my solution here. It is a solution that works without JavaScript. The secret lies in these pseudo classes:
li > a:hover + ul,
li > a:focus + ul,
li:focus-within > ul
Full HTML (Header section):
<header>
<nav>
<ul>
<li>
Page 1
<ul>
<li>
Sub page 1
</li>
<li>
Sub page 2
</li>
</ul>
</li>
<li>
Page 2
<ul>
<li>
Sub page 3
</li>
</ul>
</li>
</ul>
</nav>
</header>
Full CSS (without actual styling) – the first level elements are displayed next to each other (display: inline-block;), the second level elements are hidden and appear as soon as the parent element is active:
header ul {
list-style: none;
}
header nav > ul > li {
display: inline-block;
vertical-align: top;
}
header nav > ul > li > ul {
visibility: hidden;
opacity: 0;
}
header nav > ul > li > a:hover + ul,
header nav > ul > li > a:focus + ul,
header nav > ul > li:focus-within > ul {
visibility: visible;
opacity: 1;
}
From Heydon Pickering - Practical ARIA examples:
<nav role="navigation" aria-label="example with dropdowns">
<ul class="with-dropdowns">
<li>Home</li>
<li>
About
<ul aria-hidden="true" aria-label="submenu">
<li>Who we are</li>
<li>What we do</li>
<li>Why</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
Thanks to Shannon Youg who tried to help.
I found a solution, but I had to put some Javascript to make it work.
HTML:
<div class="my-menu">
<a id="menuUser" href="javascript:showHideMenu()" class="">
<div>
Test
</div>
</a>
<ul id="menuUserDropdown" class="menu-dropdown">
<li>
<a href="#" class="menu-dropdown-item">
Option 1
</a>
</li>
<li>
<a href="#" class="menu-dropdown-item">
Option 2
</a>
</li>
<li>
<a href="#" class="menu-dropdown-item">
Option 3
</a>
</li>
</ul>
</div>
CSS:
.my-menu a{
display: inline-block;
font-family: 'OpenSans Bold';
font-size: 16px;
color: #646464;
text-decoration: none;
cursor: pointer;
position: relative;
}
.my-menu a div{
padding: 4px 5px 4px 0;
}
.my-menu a.opened div,
.my-menu a:hover div{
background-color: #c9252b;
color: #fff;
}
.my-menu .menu-dropdown.opened{
display: block;
}
.my-menu div{
display: inline-block;
vertical-align: middle;
}
.my-menu .menu-dropdown{
display: none;
margin: 0;
position: absolute;
z-index: 30;
background-color: #FFF;
list-style: none;
padding: 0;
border: 1px solid #b4b4b4;
}
.my-menu .menu-dropdown-item{
display: block;
background-color: white;
padding: 12px;
text-decoration: none;
width: 162px;
cursor: pointer;
font-size: 16px;
color: #323232;
}
.my-menu .menu-dropdown-item:focus,
.my-menu .menu-dropdown-item:hover{
background-color: #b4b4b4;
color: #fff;
}
Javascript, well, I made with GWT, but the logic is simple:
/* Just add or remove the class "opened" from "menuUser" and "menuUserDropdown".
You can put a "blur()" and "mouseLeave()" functions
to close the menu when the user moves away the cursor or
move the focus out of the menu too. */
I know there have been a lot of similar questions but none of the solutions worked for me. the predominant answer was to have overflow: hidden; on the ul but that's no good for me because the way i have overflow coded is essential for the menu and its transitions.
essentially i have a 2 column drop-down menu. the left column is the submenu list, the right column is an image. each main menu item has a different number of submenu items and sometimes even less than the height of the img. i want to fill the background of the ul class="twinsub" but i can't get it to pick up same as the height of the tallest list whether that be the image or the submenu list. i have tried everything i can think of with no success.
here are a couple of images to illustrate what i am trying to do:
here is the code:
Updated JS FIDDLE
HTML:
<section id="menuWrapper">
<nav id="menu" class="cf" role="navigation">
<!-- Main Nav Start -->
<ul id="main-nav" class="clearfix">
<!----------------------------------------- Solutions ------------------>
<li id="technology" class="parent menu-item">Solutions
<ul class="twinsub">
<li class="twinmultisub twinleft">
<ul>
<li id="solutions-turnkey" class="menu-item">Turnkey Development
</li>
<li id="solutions-financing" class="menu-item">Financial Modeling
</li>
<li id="solutions-execution" class="menu-item">World-Class Execution
</li>
</ul>
</li>
<li class="twinmultisub twinimg">
<section>
<img class="menuimage" src="http://milkytech.com/images/industry.png" />
</section>
</li>
</ul>
</li>
<li id="technology" class="parent menu-item">Services
<ul class="twinsub">
<li class="twinmultisub twinleft">
<ul>
<li id="services-devlopment" class="menu-item">Development & Financing
</li>
<li id="services-design" class="menu-item">Design & Engineering
</li>
<li id="services-construction" class="menu-item">Construction & Procurement
</li>
<li id="services-operations" class="menu-item">Operations & Maintenance
</li>
</ul>
</li>
<li class="twinmultisub twinimg">
<section>
<img class="menuimage" src="http://milkytech.com/images/industry.png" />
</section>
</li>
</ul>
</li>
</ul>
</nav>
CSS:
#menu {
display:inline-block;
clear:both;
height:auto;
}
#menu ul {
margin:0;
}
#menu li {
float:left;
position:relative;
}
#menu > ul > li > a {
display:block;
line-height: .4em;
}
/* Submenu (second level) */
#menu li > ul {
position:absolute;
top:auto;
left:0;
width:180px;
max-height:0;
visibility: hidden;
z-index:99999;
overflow:hidden;
}
#menu ul li:hover ul {
visibility: visible;
max-height: 330px;
width: 204px;
overflow: visible;
}
#menu ul li > ul:hover {
overflow:visible;
}
#menu li > ul li {
height:36px;
width:100%;
}
#menu li > ul li:last-child {
height: 35px;
}
#menu li > ul li a {
padding: 11px 15px;
height: 35px;
color: #FFF;
width: 100%;
display: block;
}
ul.twinsub {
clear: both;
display: inline-block;
width:408px !important;
border-right: none !important;
background-color: #5d6f82 !important;
overflow: hidden;
}
ul.twinsub > li {
display: inline-block;
border-top: none !important;
background: #FFF;
line-height: 38px;
}
li.twinmultisub {
display: block;
width: 50% !important;
}
.menuimage {
width: 100% !important;
margin-left: 1px;
border-right: none;
}
li.twinimg {
float: left;
border: none;
}
li.twinleft {
clear: both;
float: left;
border-right: none !important;
}
li.twinheader {
width: 50% !important;
text-align: left;
padding-left: 14px;
font-size: .9em;
background-color: #5d6f82 !important;
color: #FFF;
opacity: 1;
}
How about adding a wrapping div around the inner ul, and add a background color to that one.
This example should make a good beginning
.wrapp {
background: #13385F;
}
body {
margin: 0;
overflow-x: hidden;
}
article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary {
display: block;
}
a {
background: transparent;
text-decoration: none;
}
a:active, a:hover {
outline: 0;
}
nav ul, nav ol {
list-style: none;
list-style-image: none;
margin: 0;
padding: 0;
}
h1, h2, h3, h4 {
margin: 0;
padding: 0;
border: 0;
vertical-align:baseline;
font-family:'Open Sans', sans-serif;
}
* {
box-sizing:border-box;
-moz-box-sizing:border-box;
}
#menu a {
text-decoration: none;
}
#menuWrapper {
display: block;
text-align: center;
margin: 15px auto 15px;
}
#menu {
display:inline-block;
clear:both;
height:auto;
-webkit-box-shadow: 0px 9px 10px -9px rgba(35, 35, 35, 0.8);
-moz-box-shadow: 0px 9px 10px -9px rgba(35, 35, 35, 0.8);
box-shadow: 0px 9px 10px -9px rgba(35, 35, 35, 0.8);
}
#menu ul {
margin:0;
}
#menu li {
float:left;
position:relative;
}
#menu > ul > li > a {
padding:25px 19px 20px;
border-bottom:3px solid transparent;
margin-right:0px;
color:#6D6E70;
font: 1em'Open Sans', sans-serif;
font-weight:bold;
text-align:center;
text-transform: uppercase;
display:block;
line-height: .4em;
}
#menu > ul > li:last-child > a {
font-size: 1em;
}
#menu > ul > li:hover > a {
color:#5999db;
border-bottom: 3px solid #5999db;
}
#menu > ul li.selected > a, #menu > ul li.selected:hover > a {
color:#3F9944;
border-color:#FFF100;
}
/* Submenu (second level) */
#menu li > .wrapp > ul {
position:absolute;
top:auto;
left:0;
width:180px;
max-height:0;
/* -webkit-box-shadow: 0px 2px 7px 1px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 0px 2px 7px 1px rgba(0, 0, 0, 0.4);
box-shadow: 0px 2px 7px 1px rgba(0, 0, 0, 0.4); */
visibility: none;
z-index:99999;
overflow:hidden;
-webkit-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
-moz-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
-o-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
-ms-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
transition: max-height 0.2s ease, visibility 0s linear 0.5s;
background: inherit !important;
}
#menu ul li:hover ul {
visibility: visible;
max-height: 330px;
width: 204px;
transition-delay: 0s;
overflow: visible;
border: 1px solid #EEE;
border-top: 0;
}
#menu ul li > ul:hover {
overflow:visible;
}
#menu li > ul li {
height:36px;
width:100%;
border-bottom: 1px solid #EEE;
padding-top:0;
font-weight: 600;
background-color: #13385F;
color: #FFF;
opacity: 1;
}
#menu li > ul li:last-child {
border-bottom:none;
height: 35px;
}
#menu li > ul li a {
background: rgba(19, 57, 95, 0.3);
padding: 11px 15px;
height: 35px;
color: #FFF;
width: 100%;
font: 10px'Open Sans', sans-serif;
font-weight: bold;
text-align: left;
text-transform: uppercase;
display: block;
opacity: 1;
}
#menu li > ul li:hover > a {
color: #3B3B3B;
background: #5999db;
}
#menu li > ul li.selected > a, #menu li > ul li.selected:hover > a {
color: #3B3B3B;
background: #FFF;
}
ul.twinsub {
clear: both;
display: inline-block;
width:408px !important;
border-right: none !important;
background-color: #5d6f82 !important;
overflow: hidden;
}
ul.twinsub > li {
display: inline-block;
border-top: none !important;
background: #FFF;
line-height: 38px;
}
li.twinmultisub {
display: block;
width: 50% !important;
}
.menuimage {
width: 100% !important;
margin-left: 1px;
border-right: none;
line-height: 0 !important;
font-size: 0 !important;
}
li.twinimg {
float: left;
border: none;
}
li.twinimg section {
line-height: 0;
}
.borderleft {
border-left: 1px solid #EEE;
}
li.twinleft {
clear: both;
float: left;
border-right: none !important;
}
li.twinheader {
width: 50% !important;
text-align: left;
padding-left: 14px;
font-size: .9em;
background-color: #5d6f82 !important;
color: #FFF;
opacity: 1;
}
<section id="menuWrapper">
<nav id="menu" class="cf" role="navigation">
<!-- Main Nav Start -->
<ul id="main-nav" class="clearfix">
<!----------------------------------------- Solutions ------------------>
<li id="technology" class="parent menu-item">Solutions
<div class="wrapp">
<ul class="twinsub">
<li class="twinmultisub twinleft">
<ul>
<li id="solutions-turnkey" class="menu-item">Turnkey Development
</li>
<li id="solutions-financing" class="menu-item">Financial Modeling
</li>
<li id="solutions-execution" class="menu-item">World-Class Execution
</li>
</ul>
</li>
<li class="twinmultisub twinimg">
<section>
<img class="menuimage" src="http://milkytech.com/images/industry.png" />
</section>
</li>
</ul>
</div>
</li>
<li id="technology" class="parent menu-item">Services
<div class="wrapp">
<ul class="twinsub">
<li class="twinmultisub twinleft">
<ul>
<li id="services-devlopment" class="menu-item">Development & Financing
</li>
<li id="services-design" class="menu-item">Design & Engineering
</li>
<li id="services-construction" class="menu-item">Construction & Procurement
</li>
<li id="services-operations" class="menu-item">Operations & Maintenance
</li>
<li id="services-construction" class="menu-item">Construction & Procurement
</li>
<li id="services-operations" class="menu-item">Operations & Maintenance
</li>
</ul>
</li>
<li class="twinmultisub twinimg">
<section>
<img class="menuimage" src="http://milkytech.com/images/industry.png" />
</section>
</li>
</ul>
</div>
</li>
</ul>
</nav>
</section>
Just remeber to fix the css on the menu. And the section around the image, and the image itself needs a line-height of 0.
How can I change my main navigation bar so that when I go to the "About", "From Internet", "By Me" dropdown lists and then hover over a second layer option both the active top link and active second link remain the same color:
Like here this example here, when you go to hyper link 4 in the last sub-option both active options are green at the same time! How can I do that in mine?
body {
background: #DCDCD8;
}
h2 {
text-align: center;
color: #CCC;
}
a {
display: block;
text-decoration: none;
width: 100%;
height: 100%;
color: #999;
}
/* NAVIGATION */
.navigation {
list-style: none;
padding: 0;
width: 250px;
height: 40px;
margin: 0;
background: #F5F5F0;
position: relative;
z-index: 100;
display: inline-block;
vertical-align: top;
left: 5px;
top: 0px;
}
.navigation,
.navigation a.main {
border-radius: 4px;
}
.navigation:hover,
.navigation:hover a.main {
border-radius: 4px 4px 0 0;
}
.navigation a.main {
height: 40px;
font: bold 15px/40px arial, sans-serif;
text-align: center;
text-decoration: none;
color: #FFF;
transition: 0.2s ease-in-out;
position: relative;
z-index: 100;
display: inline-block;
}
.navigation li {
width: 250px;
height: 40px;
background: #F7F7F7;
font: normal 14px/40px arial, sans-serif !important;
color: #999;
text-align: center;
margin: 0;
transform-origin: 50% 0%;
transform: perspective(350px) rotateX(-90deg);
box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.05);
}
.navigation li:nth-child(even) {
background: #F5F5F5;
}
.navigation li:nth-child(odd) {
background: #EFEFEF;
}
.navigation li.n1 {
transition: 0.2s linear 0.8s;
}
.navigation li.n2 {
transition: 0.2s linear 0.6s;
}
.navigation li.n3 {
transition: 0.2s linear 0.4s;
}
.navigation li.n4 {
transition: 0.2s linear 0.2s;
}
.navigation li.n5 {
border-radius: 0px 0px 4px 4px;
transition: 0.2s linear 0s;
}
.navigation:hover li {
transform: perspective(350px) rotateX(0deg);
transition: 0.2s linear 0s;
}
.navigation:hover .n2 {
transition-delay: 0.2s;
}
.navigation:hover .n3 {
transition-delay: 0.4s;
}
.navigation:hover .n4 {
transition-delay: 0.6s;
}
.navigation:hover .n5 {
transition-delay: 0.8s;
}
#option:hover,
#blue:hover {
color: white;
background-color: #19A3FF;
}
#option:active {
color: white;
background-color: #1c5f8d;
}
#blue:active {
color: white;
background-color: #1c5f8d;
}
#option {
color: black;
}
#blue {
color: black;
}
.navigation ul {
display: none;
position: relative;
top: -40px;
left: 250px;
list-style-type: none;
margin: 0;
padding: 0;
}
.navigation li:hover ul {
display: block;
}
#nav {
min-width: 1020px;
}
<div style="background:#F5F5F0;">
<div>
<div style="float:left; margin-top:0; left:20px;">
<img class="buzz" src="community-activism.png" width="80" height="80" />
</div>
<h1 style="color:black; opacity:40;" class="shrink"><strong> Social Activism</strong></h1>
</div>
<br />
<div id="nav">
<div id="nav_wrapper" style="margin:0 auto; display:inline-block;">
</div>
<div>
<ul class="navigation">
<a class="main" href="#url" style="color:black;" id="blue">Home</a>
</ul>
<ul class="navigation">
<a class="main" href="#url" style="color:black;" id="blue">About ▼</a>
<li class="n1" id="selection">
Poems ►
<ul>
<li class="n6">
Poem From Internet
</li>
<li class="n7">
Poem By Me
</li>
</ul>
</li>
<li class="n2" id="selection">
Informational Media
</li>
<li class="n3" id="selection">
Visual/Video
</li>
<li class="n4" id="selection">
Photo Essay
</li>
<li class="n5" id="selection">
Me
</li>
</ul>
<ul class="navigation">
<a class="main" href="#url" style="color:black;" id="blue">From Internet ▼ </a>
<li class="n1" id="selection">
Poem
</li>
<li class="n2" id="selection">
Informational Media
</li>
<li class="n3" id="selection">
Visual/Video
</li>
<li class="n4" id="selection">
Photo Essay
</li>
</ul>
<ul class="navigation">
<a class="main" href="#url" style="color:black;" id="blue">By Me ▼</a>
<li class="n1" id="selection">
Poem
</li>
<li class="n2" id="selection">
Informational Media
</li>
<li class="n3" id="selection">
Visual/Video
</li>
<li class="n4" id="selection">
Photo Essay
</li>
</ul>
</div>
</div>
</div>
Your nested list needs to be changed slightly. The only valid element directly inside an unordered list <ul> is the list item element <li> and not <a>
This example is basic and made purely to demonstrate a method to colour the backgrounds.
The Background CSS
The background is applied to the list items child <a> element.
Give a background color to the direct child of the hovered list item (this will apply to all top level list items):
li:hover > a {
background: pink;
}
Give a background to the list items link that is being hovered:
li a:hover {
background: purple;
}
That will give you this (purple item is hovered):
Complete Example
* {
margin: 0;
padding: 0;
}
body {
font-family: arial, sans-serif;
}
a {
text-decoration: none;
color: #000;
font-weight: bold;
display: block;
padding: 5px 10px;
}
ul {
list-style: none;
}
ul li {
display: inline-block;
vertical-align: top;
}
ul li .layer li,
ul li:hover .layer .layer li {
display: none;
}
ul li:hover .layer li,
ul li .layer li:hover .layer li {
display: block;
}
li:hover > a {
background: pink;
}
li a:hover {
background: purple;
}
<ul>
<li>Home</li>
<li>Hover Me
<ul class="layer">
<li>Option</li>
<li>Option</li>
<li>Option</li>
<li>Hover Me
<ul class="layer">
<li>Option</li>
<li>Option</li>
<li>Option</li>
</ul>
</li>
</ul>
</li>
</ul>
I have a navigation menu that I'm trying to get to work, but the submenus keep switching to another submenu whenever I hover over it. How can I get it so that the right menu stays up when I hover over it?
jsfiddle: http://jsfiddle.net/SHQwm/
.hoverBar {
position: relative;
border: 1px solid #d6d6d6;
background: #fff;
padding: 15px 20px;
height: 100px;
}
ul {
margin: 0;
padding: 0;
width: 1152px;
}
.mainmenu > li {
list-style: none;
float:left;
text-align: center;
}
ul.mainmenu > li a {
font-family: 'Open Sans', sans-serif;
padding: 0 10px;
font-size: 11px;
text-decoration: none;
text-transform: uppercase;
}
ul li ul {
opacity: 0;
transition: opacity .15s ease-in-out;
-moz-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
-o-transition: opacity .15s ease-in-out;
list-style-type: none;
text-align: left;
float: left;
width: 100%;
position: absolute;
z-index: 60;
left: 0;
padding-top: 30px;
}
ul li:hover ul {
opacity: 1;
}
ul li ul li {
float: left;
text-align: left;
border-top: #4c4c4c 1px solid;
border-bottom: #303030 1px solid;
border-radius: 2px;
margin-bottom: 0;
padding: 10px 0;
white-space: nowrap;
width: auto;
}
ul li ul li:hover {
background-color: #008000;
}
.floatr {
position: absolute;
top: 10px;
z-index: 50;
width: 100px;
height: 30px;
background : #ebebeb;
opacity: 0.25;
-ms-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
border-top: solid 1px #00aced;
border-bottom: solid 1px #00aced;
}
.mainmenu > li:hover > a {
opacity: 1;
}
ul li ul li a {
display: block;
padding: 0px;
line-height: 14px;
font-size: 12px;
color: #000;
font-family: 'Open Sans', sans-serif;
text-transform: none !important;
text-align: left;
}
ul li:hover ul li {
display:block;
}
.mainmenu {
height: 100px;
}
#jobBank {
left: 450;
width: 210px;
}
And the HTML:
<nav class="head_nav">
<div class="hoverBar" >
<ul class="mainmenu">
<li class="active">About
<ul style="background-color: red;">
<li>Mission</li>
<li>Board Members</li>
<li>Staff</li>
<li>Members</li>
<li>Task Forces</li>
</ul>
</li>
<li>Events
<ul style="background-color: green;">
<li>Description</li>
<li>Registration with Outlook ICS</li>
<li>Online Payment</li>
<li>Email auto-reminders</li>
<li>Multiple registrants allowed</li>
</ul>
</li>
<li>Galleries
<ul style="background-color: blue;">
<li>EXAMPLE: Executive Board</li>
<li>EXAMPLE: Single Page or Blog Page</li>
<li>EXAMPLE: Photo Gallery</li>
</ul>
</li>
<li>Educational Resources</li>
<li>Economic Development
<ul style="background-color: yellow;">
<li>Major Corporations/Global Businesses</li>
<li>Maps</li>
<li>Available Properties</li>
<li>Communities Represented</li>
<li>Demographics</li>
<li>Workforce</li>
<li>Taxes</li>
<li>Transportation</li>
<li>Utilities</li>
<li>Incentives & Financing</li>
<li>Report and Publications</li>
</ul>
</li>
</li>
<li>Media Room
<ul>
<li class="first">Press Releases</li>
<li>Media Kit Information</li>
<li>Blog</li>
<li>Link to Logo & Standards</li>
<li>Link to Photo Gallery</li>
<li>Twitter, Facebook, LinkedIn, Flickr</li>
<li>Speakers Bureau List/info</li>
<li>Fact Sheet</li>
<li class="last">Media Relations Contact</li>
</ul>
</li>
<li>Job Bank
<ul id="jobBank">
<li class="first">Member Add/Edit/Delete</li>
<li class="last">Time Expire</li>
</ul>
</li>
</ul>
<div class="floatr"></div>
</div>
</nav>
Remove opacity: 0 from ul li ul. Replace it with display: none;. Remove opacity: 1 from ul li:hover ul. Replace it with display: block;. Currently, all of the subnavigations are there, you just can't see them. Setting them to display: none; by default will only display the correct one when the parent navigation element is hovered and will remove the issue you're having. http://jsfiddle.net/SHQwm/5/