I have this css code:
.nav li li a { /* sub menu list */
display: block;
background: #F36F25;
position: relative;
z-index:100;
border-top: 1px solid #ffffff;
}
.nav > li > ul > li.hover > a { /* sub menu list hover */
background:#FFFFFF;
}
.nav > li > ul > li.hover > ul > li { /* sub sub menu list hover */
background:#F36F25;
}
how can i ensure that the parent item stays active when hovering over a child item?
Also, how can i get an active class working for parent items and also if a child item has the active class i want the parent and child item to have the class assigned
We have this html :
<div id="nav">
<ul>
<li>Home</li>
<li>Menu 1
<ul>
<li>Sub menu</li>
<li>Sub menu</li>
<li>Sub menu</li>
<li>**Sub menu
<ul>
<li>Sub menu</li>
<li>Sub menu</li>
<li>Sub menu</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
And this CSS:
* {margin: 0 auto; padding: 0;}
a{text-decoration: none;}
#nav ul {
list-style-type: none;
height: 32px;
background:#333;
width: auto;
}
#nav ul li {
float: left;
height: 32px;
position: relative;
}
#nav ul li a {
float:left;
line-height: 32px;
color:#fff;
padding: 0 7px;
}
#nav ul li:hover {background:#ff6600;}
#nav ul li:hover > ul {display: block;}
#nav ul li ul {
display: none;
position: absolute;
top: 32px;
left: 0;
width: 100px;
height: auto;
}
#nav ul li ul li, #nav ul li ul li a {
float: none;
display: block;
}
#nav ul li ul li ul {
top: 0;
left: 100px;
}
this is Demo link :
http://jsfiddle.net/ebadgh/c4x7gwvw/
Related
In following code on hover of menu1 I want to show submenu but it will not work.I applied below css. Please modified the code where I am wrong.
HTML
<div class="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>
Menu 1
<div class="sub_divsavedfun" id="Functions_1-5">
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>
Sub Menu 4
<ul>
<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>
<li>Sub Menu 5</li>
</ul>
</div>
</li>
</ul>
</div>
CSS
<style>
.primary_nav_wrap
{
margin-top:15px
}
.primary_nav_wrap ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
.primary_nav_wrap ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
.primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
.primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}
.primary_nav_wrap ul li:hover
{
background:#f6f6f6
}
.primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
.primary_nav_wrap ul ul li
{
float:none;
width:200px
}
.primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}
.primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
.primary_nav_wrap ul li:hover > ul
{
display:block
}
</style>
If I remove <div class="sub_divsavedfun" id="Functions_1-5"> then it will work.But as per requirement I have add div tag.
add this css
.primary_nav_wrap ul li:hover .sub_divsavedfun > ul
{
display:block
}
https://jsfiddle.net/mrob21h7/1/
Add this in css and it's working fine
You add div before the sub ul so, in css .primary_nav_wrap ul li:hover > ul not found any ul. because structure of HTML element is now .primary_nav_wrap ul > li > div > ul
.primary_nav_wrap ul li:hover > div > ul
{
display:block
}
Check this Demo
You have div direct child of li not ul. So just replace following code:
.primary_nav_wrap ul li:hover > ul {
display: block
}
to :
.primary_nav_wrap ul li:hover div > ul, .primary_nav_wrap ul li:hover > ul {
display: block
}
Working Snippet :
.primary_nav_wrap {
margin-top: 15px
}
.primary_nav_wrap ul {
list-style: none;
position: relative;
float: left;
margin: 0;
padding: 0
}
.primary_nav_wrap ul a {
display: block;
color: #333;
text-decoration: none;
font-weight: 700;
font-size: 12px;
line-height: 32px;
padding: 0 15px;
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif
}
.primary_nav_wrap ul li {
position: relative;
float: left;
margin: 0;
padding: 0
}
.primary_nav_wrap ul li.current-menu-item {
background: #ddd
}
.primary_nav_wrap ul li:hover {
background: #f6f6f6
}
.primary_nav_wrap ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
padding: 0
}
.primary_nav_wrap ul ul li {
float: none;
width: 200px
}
.primary_nav_wrap ul ul a {
line-height: 120%;
padding: 10px 15px
}
.primary_nav_wrap ul ul ul {
top: 0;
left: 100%
}
/* CODE REPLACED BY BELOW
.primary_nav_wrap ul li:hover > ul {
display: block
}
*/
/*Code added */
.primary_nav_wrap ul li:hover div > ul, .primary_nav_wrap ul li:hover > ul {
display: block
}
<div class="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home
</li>
<li>
Menu 1
<div class="sub_divsavedfun" id="Functions_1-5">
<ul>
<li>Sub Menu 1
</li>
<li>Sub Menu 2
</li>
<li>Sub Menu 3
</li>
<li>
Sub Menu 4
<ul>
<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>
<li>Sub Menu 5
</li>
</ul>
</div>
</li>
</ul>
</div>
I have a menu drop down list which is done using css and html. Now, I want to have an extension of sub menu on the existing sub menu, when I hover the "Audit Report for example, it should show another sub menu vertically. How can I achieve that? This is my existing codes in css and html.
css
.menuPanel
{
width: auto;
height: 32px;
top: 5px;
border-bottom: 1px solid #808080;
background-color: #4f4545;
}
.nav,.nav ul
{
list-style: none;
margin:0;
padding:0;
}
.nav {
position:relative;
left: 2px;
height: auto;
}
.nav ul
{
height:0;
left:0;
overflow: hidden;
position:absolute;
}
.nav li
{
float:left;
position:relative;
}
.nav li a
{
-moz-transition:1.0s;
-o-transition:1.0s;
-webkit-transition:1.0s;
transition:1.0s;
background-color: #4f4545;
display: block;
color:#FFF;
text-decoration:none;
font-size:12px;
line-height:32px;
padding:0px 30px;
}
.nav li:hover > a
{
background: #8CCA33;
border-color: #6E67A6;
color:#fff;
}
.nav li:hover ul.subs
{
height:auto;
width: 250px;
z-index: 10;
}
.nav ul li
{
-moz-transition:0.3s;
-o-transition:0.3s;
-webkit-transition:0.3s;
opacity:0;
transition:0.3s;
width:100%;
}
.nav li:hover ul li
{
opacity:1;
-moz-transition-delay:0.2s;
-o-transition-delay:0.2s;
-webkit-transition-delay:0.2s;
transition-delay:0.2s;
}
.nav ul li a
{
background: #4f4545;
border: 1px solid #808080;
color:#fff;
line-height:1px;
-moz-transition:1.5s;
-o-transition:1.5s;
-webkit-transition:1.5s;
transition:1.5s;
}
.nav li:hover ul li a
{
line-height:32px;
}
.nav ul li a:hover
{
background:#8CCA33;
}
aspx page design
<ul class="nav">
<li>HOME</li>
<li>FILE ▾
<ul class="subs">
<li>Tenants List</li>
<li>Users List</li>
<li>Tenant Rental</li>
</ul>
</li>
<li>REPORTS ▾
<ul class="subs">
<li>Audit Reports
<ul>
<li><a href='#'>Sub Product</a></li>
<li><a href='#'>Sub Product</a></li>
</ul>
</li>
<li>Leasing Reports</li>
<li>Marketing Reports</li>
</ul>
</li>
<li id="admin" visible="true" runat="server">ADMIN ▾
<ul class="subs">
<li>System Logs</li>
<li>User Request</li>
</ul>
</li>
<li>LOG-OUT
</li>
</ul>
</div>
You have to do a new CSS-Style for .nav .subs ul for the whole block or .nav .subs ul li for a single element of the block
example:
.nav .subs li ul
{
max-height: 0;
-moz-transition:1.5s;
-o-transition:1.5s;
-webkit-transition:1.5s;
transition:1.5s;
}
.nav .subs li:hover > ul
{
max-height: 300px;
height: auto;
}
.nav .subs li ul
{
left: 250px;
top: 0;
overflow: hidden;
}
this just shows the new block, if you hover over a submenu-item, now you only have to style it and place it whereever you want it
Example on JSFiddle:
http://jsfiddle.net/4sym7ry0/3/
Do Nested Unorderlist and orderedlist inside your ListItem
Check this For More Info :
http://www.thecodingguys.net/blog/css3-create-a-vertical-menu-with-sub-menu
I have made a navigation menu bar and also two dropdown menus with 3 items each. My problem is that, below this menu, I have a slider, so when I hover my dropdown, two of the three items are hidden behind the slider.
How can I solve this?
My HTML:
<div id="nav">
<div id="nav_wrapper">
<ul>
<li>item #1
</li>
<li> item #2
</li>
<li> dropdown #1
<ul>
<li>dropdown #1 item #1
</li>
<li>dropdown #1 item #2
</li>
<li>dropdown #1 item #3
</li>
</ul>
</li>
<li> dropdown #2
<ul>
<li>dropdown #2 item #1
</li>
<li>dropdown #2 item #2
</li>
<li>dropdown #2 item #3
</li>
</ul>
</li>
<li> item #3
</li>
</ul>
</div>
</div>
My CSS:
#nav {
background-color: #222;
}
#nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: left;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #333;
}
#nav ul li a, visited {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
I think the problem is on your z-index properties.
You need to set on #nav and #slider elements position and z-index properties.
#nav {
position: relative;
z-index: 2;
}
#slider{
position: relative;
z-index: 1;
}
That means the #nav menu will be front slider when you set a z-index property large than z-index on #slider. Have you attention that z-index doesn't work if you not set element position property like relative or absolute.
You can look this link for example - http://css-tricks.com/almanac/properties/z/z-index/
I have created this kind of menu.
The CSS classes used are as follows.
#main_nav {
padding: 3px 0px 3px 0px;
z-index: 300 !important;
}
#main_nav ul {
list-style:none;
position:relative;
float:left;
margin:0;
padding:0;
background: #888;
z-index: 300 !important;
min-width: 150px;
white-space: nowrap;
}
#main_nav ul a {
display:block;
text-decoration:none;
font-size:12px;
line-height:32px;
padding:0 15px;
color: #fff;
font-family: "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif;
}
#main_nav ul li {
position:relative;
float:left;
margin:0;
padding:0;
}
#main_nav ul li.current-menu-item {
background:#ddd;
}
#main_nav ul li:hover {
background: #008000;
}
#main_nav ul ul {
display:none;
position:absolute;
top:100%;
left:0;
background:#888;
padding:0;
}
#main_nav ul ul li {
float:none;
white-space: nowrap;
width: 100%;
}
#main_nav ul ul a {
line-height:120%;
padding:10px 15px;
}
#main_nav ul ul ul {
top:0;
left:100%;
}
#main_nav ul li:hover > ul {
display:block;
}
#main_nav > ul > li {
display: inline-block;
float: none;
margin: 0 -3px 0 0;
}
.menu li:last-of-type { border-right: none; }
.menu li > a:after {float: right; margin-left: 5px; content: '\25BA'; }
.menu > li > a:after {float: right; margin-left: 5px; content: '\25BC'; }
.menu li > a.only-child:after { margin-left: 0; content: ''; }
The HTML code :
$(document).ready(function() {
$("a:only-child").addClass("only-child");
});
<div id="main_nav">
<ul class="menu">
<li class="current-menu-item">Home</li>
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 4
<ul>
<li>Deep Menu 1
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
<li>Category 5</li>
</ul>
</li>
<li>Deep Menu 2</li>
</ul>
</li>
<li>Sub Menu 5</li>
</ul>
</li>
<li>Menu 2</li>
<li>Menu 3</li>
</ul>
</div>
This works fine except float: right in the following CSS classes.
.menu li > a:after {float: right; margin-left: 5px; content: '\25BA'; }
.menu > li > a:after {float: right; margin-left: 5px; content: '\25BC'; }
float: right; is meant to float a corresponding arrow to the right of the menu. It however, does not allow the menu text and the arrow to inline properly.
The discrepancy is clearly visible on FireFox.
The picture has been taken from FireFox (31.0). The arrows are not lined up properly with the text. The menu looks good on Google Chrome (36.0.1985.143 m) and Internet Explorer (8).
How can arrows be aligned right and lined up properly?
It looks like instead of setting float:right you needed to use
position: absolute;
right: 0px;
As shown here
I'm trying to make a vertical dropdown menu but doesn't seem to work. It currently doesn't display any text, just a bar going across the top of the page. It is being pushed to be by by 115px for due to requirements. Here's the HTML:
<div id="wrapper">
<h1>Flags </h1>
<nav>
<ul>
<li>Introduction</li>
<li>History</li>
<li>National Flags</li>
<li>International Maritime Signal Flags
<ul>
<li>Maritime Signals: Letters</li>
<li>Maritime Signals: Numbers</li>
</ul>
</li>
</ul>
</nav>
Here is the CSS:
nav {
height:30px;
}
nav ul {
background-color: #5d2c2c;
padding: 0;
list-style: none;
position: relative;
bottom: 115px;
display: block;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: right;
bottom: 115px;
position: relative;
}
nav ul li a {
display: block; padding: 5px 5px;
color: #FFF; text-decoration: none;
text-align:right;
}
nav ul ul {
background: #5d2c2c; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #000;
border-bottom: 1px solid #575f6a;
position: relative;
}
The CSS needed a little work on
Try this FIDDLE it'll work
This was missing:
nav ul li:nth-child(4) ul { display:none; }
nav ul li:nth-child(4):hover ul { display:block; color:red; }
and bottom was removed from this one
nav ul li {
float: left;
position: relative;
}
I found this link the other day, it's an step by step guide with full examples, check it out: http://www.adam-bray.com/blog/91/Easy+HTML+5+%26+CSS+3+Navigation+Menu/
check this fiddle , a similar implementation
<nav>
<ul>
<li class="header">
People
<ul class="content">
<li>Sub 1</li>
<li>Sub 2</li>
</ul>
</li>
<li class="header">
Animals
<ul class="content">
<li>Sub 1</li>
<li>Sub 2</li>
</ul>
</li>
</ul>
</nav>
nav > ul{}
nav > ul > li{float:left;margin:0 5px;background:#cc3333;}
.header li a{background:#eee;color:#cc3333;}
.header li a:hover{color:#fff;background:#cc3333;}
ul{padding:0;}
li{list-style-type:none;}
a{color:#fff;text-decoration:none;padding:5px;display:block;text-align:center;}
.content{
display:none;
}
.header:hover > .content{display:block;}