I have 1 side menu in my main page of website. And some of the list have have sub menu. And on hover i want to display it. Firstly i am display it none and then on display it on hover but it is not displaying.
#menu {
width: 15%;
height: 100%;
background: #424242;
color: white;
float: left;
}
#menu ul {
margin: 0;
padding: 0;
}
#menu li {
list-style: none;
font-size: 20px;
padding: 15px 20px;
cursor: pointer;
}
#menu li:hover {
background-color: #90CAF9;
}
#menu li.active {
background-color: #2196F3;
}
#menu li ul {
display: none;
}
#menu li:hover ul {
display: block;
position: absolute;
left:100%
}
<div id="menu">
<ul>
<li onClick="Dashboard();">Dashboard</li>
<li>Employee >
<ul>
<li>Add Employee</li>
<li>Employee View</li>
</ul>
</li>
<li>Leave</li>
<li>Salary</li>
<li>Change Password</li>
</ul>
</div>
#menu {
width: 150px;
height: 100%;
background: #424242;
color: white;
float: left;
}
#menu ul {
margin: 0;
padding: 0;
}
#menu li {
list-style: none;
font-size: 20px;
padding: 15px 20px;
cursor: pointer;
}
#menu li:hover {
background-color: #90CAF9;
}
#menu li.active {
background-color: #2196F3;
}
#menu ul li ul {
display: none;
}
#menu ul li.submenu {
position: relative
}
#menu ul li.submenu ul {
position: absolute;
left: 150px;
width: 200px;
top: 0;
background: #333
}
#menu ul li.submenu:hover ul {
display: inline-block
}
<div id="menu">
<ul>
<li onClick="Dashboard();">Dashboard</li>
<li class="submenu">Employee >
<ul>
<li>Add Employee</li>
<li>Employee View</li>
</ul>
</li>
<li>Leave</li>
<li class="submenu">Salary
<ul>
<li>Add Employee</li>
<li>Employee View</li>
</ul>
</li>
<li>Change Password</li>
</ul>
</div>
Also Add .submenu class to submenu dropdown parent li.
Related
I would like to know how to highlight each menu item in the following drop down menu. When I hover over the current menu with mouse it highlights the | characters also next to them. How can I solve this? Thank you for all information.
The html code is :
#menu {
width: 960px;
margin-left: auto;
margin-right: auto;
text-align: center;
position: relative;
z-index: 1;
}
#primary_nav_wrap {
margin-left: auto;
margin-right: auto;
margin-top: 5px;
text-align: center;
/*margin-left:50px; */
}
#primary_nav_wrap ul {
list-style: none;
position: relative;
/*float:left;*/
text-align: center;
margin: 0;
padding: 0;
}
#primary_nav_wrap ul a {
/*display:block;*/
color: #333;
text-decoration: none;
font-weight: 500;
font-size: 14px;
text-transform: uppercase;
line-height: 32px;
padding-top: 10px;
font-family: 'Raleway', sans-serif;
display: inline-block;
}
#primary_nav_wrap ul li {
display: inline-block;
position: relative;
/*float:left;*/
margin: 0px;
padding: 0px;
}
#primary_nav_wrap ul li a {}
#primary_nav_wrap ul li a:after {
margin-left: 10px;
margin-right: 10px;
content: " | ";
}
#primary_nav_wrap ul li.last a:after {
content: none !important;
}
#primary_nav_wrap ul li li.submenu a:after {
content: none !important;
}
#primary_nav_wrap ul li a:hover {
background: #f6f6f6;
}
#primary_nav_wrap ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
opacity: .8;
padding: 0;
}
#primary_nav_wrap ul ul li {
float: none;
text-align: left;
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: inline-block;
}
<div id="menu">
<nav id="primary_nav_wrap">
<ul>
<li class="currentmenuitem">Home
</li>
<li>about us
</li>
<li>day course
<ul>
<li class="submenu">3 Day Course
</li>
<li class="submenu">6 Day Course
</li>
</ul>
</li>
<li>short course
<ul>
<li class="submenu">Pasta course
</li>
<li class="submenu">Pizza course
</li>
<li class="submenu">Fettucine course
</li>
</ul>
</li>
<li>Tours
</li>
<li>recipes
</li>
<li>reviews
</li>
<li>Contact Us
</li>
<li class="last">Location
</li>
</ul>
</nav>
</div>
Change the placement of your pseudo element from the a to li. Do this for all CSS selectors that are targeting the a.
Update #primary_nav_wrap ul li a:after {} to #primary_nav_wrap ul li:after {}
Below is an example of your menu with improved markup and reduced CSS (lot's of overlap of CSS properties that were not needed).
#menu {
width: 960px;
margin-left: auto;
margin-right: auto;
}
#primary_nav_wrap ul,
#primary_nav_wrap li {
margin: 0;
padding: 0;
list-style: none;
}
#primary_nav_wrap li {
display: inline-block;
position: relative;
}
#primary_nav_wrap a {
color: #333;
text-decoration: none;
font-weight: 500;
font-size: 14px;
text-transform: uppercase;
line-height: 32px;
font-family: 'Raleway', sans-serif;
display: inline-block;
}
#primary_nav_wrap a:hover {
background: #f6f6f6;
}
#primary_nav_wrap ul > li:after {
margin-left: 10px;
margin-right: 10px;
content: " | ";
}
#primary_nav_wrap ul > li:hover .submenu {
display: block;
}
#primary_nav_wrap .submenu > li {
float: none;
text-align: left;
width: 200px;
}
#primary_nav_wrap .submenu {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
opacity: .8;
padding: 0;
}
#primary_nav_wrap ul > li.last:after,
#primary_nav_wrap .submenu > li:after {
content: none !important;
}
#primary_nav_wrap .submenu a {
line-height: 120%;
padding: 10px 15px;
}
<div id="menu">
<nav id="primary_nav_wrap">
<ul>
<li class="currentmenuitem">Home
</li>
<li>about us
</li>
<li>day course
<ul class="submenu">
<li>3 Day Course
</li>
<li>6 Day Course
</li>
</ul>
</li>
<li>short course
<ul class="submenu">
<li>Pasta course
</li>
<li>Pizza course
</li>
<li>Fettucine course
</li>
</ul>
</li>
<li>Tours
</li>
<li>recipes
</li>
<li>reviews
</li>
<li>Contact Us
</li>
<li class="last">Location
</li>
</ul>
</nav>
</div>
CSS drop-down menu not showing sub-menu on hover, but find out the actual problem. Below are the HTML and CSS. Please see fiddle.
It looks display: block; has no effect at all.
body {
background-color: #eee;
padding: 0;
}
.inline-menu,
.inline-menu ul {
list-style: none;
padding: 0;
margin: 0;
}
.inline-menu > li {
display: inline-block;
padding-right: 25px;
}
.inline-menu a {
text-decoration: none;
}
.inline-menu > li > ul {
display: none;
}
.inline-menu > li > ul:hover {
display: block;
}
<nav>
<span class="logo"></span>
<ul class="inline-menu left-menu">
<li>L-A
<ul>
<li>1
</li>
<li>2
</li>
</ul>
</li>
<li>L-B
<ul>
<li>1
</li>
<li>2
</li>
</ul>
</li>
</ul>
</nav>
You are applying hover to the wrong element- use this:
.inline-menu > li:hover > ul{
display: block;
}
instead of .inline-menu > li > ul:hover
body{
background-color: #eee;
padding: 0;
}
.inline-menu,
.inline-menu ul{
list-style: none;
padding: 0;
margin: 0;
}
.inline-menu > li{
display: inline-block;
padding-right: 25px;
}
.inline-menu a{
text-decoration: none;
}
.inline-menu > li > ul{
display: none;
}
.inline-menu > li:hover > ul{
display: block;
}
<nav>
<span class="logo"></span>
<ul class="inline-menu left-menu">
<li>L-A
<ul>
<li>1</li>
<li>2</li>
</ul>
</li>
<li>L-B
<ul>
<li>1</li>
<li>2</li>
</ul>
</li>
</ul>
</nav>
* {
margin: 0px;
padding: 0px;
}
#menu ul {
list-style: none;
}
#menu ul li {
float: left;
width: 150px;
height: 50px;
background-color: #0C3;
border: 1px solid #FFF;
text-align: center;
line-height: 50px;
position: relative;
}
#menu ul li a {
color: #CC0;
display: block;
text-decoration: none;
}
#menu ul li a:hover {
background: #C30;
color: #FFF;
}
#menu ul ul {
display: none;
position: absolute;
}
#menu ul li:hover> ul {
display: block;
}
<div id="menu">
<ul>
<li>L-A
<ul>
<li>A
</li>
<li>B
</li>
</ul>
</li>
<li>L-B
<ul>
<li>C
</li>
<li>D
</li>
</ul>
</li>
</li>
</div>
</div>
i have a menu i'm developing at this link:
http://events.discoverportland.net/
The menu should load to a blue square just to the right of the discover portland logo. There are serveral nested ul's in the menu, the problem i'm having is getting them to load to the side of the menus above them As it load now, you can't get to the teritairy links unless you move VERY fast.
Is there any way to get the uls to load inline as i'm hovering over them, or is there a better solution?
this my nav html:
<nav>
<div class="clearfix hd8 suckerfish" >
<ul id="md">
<li>Home2</li>
<li>Neighborhoods
<ul>
<li>Northwest
<ul>
<li>Pearl District</li>
<li>Oldtown-Chinatown </li>
<li>Nob Hill</li>
</ul>
</li>
<li>Southwest
<ul>
<li>West End</li>
<li>Riverplace-South Waterfront</li>
<li>Downtown</li>
</ul>
</li>
<li>Southeast
<ul>
<li>Sellwood-Westmoreland</li>
<li>Hawthorne</li>
<li>Clinton-Division</li>
</ul>
</li>
<li>Northeast
<ul>
<li>Alberta</li>
<li>Lloyd District</li>
<li>Hollywood District</li>
</ul>
</li>
<li>North
<ul>
<li>Mississippi</li>
<li>Williams</li>
<li>St. Johns</li>
</ul>
</li>
</ul>
</li>
<li>Itineraries</li>
<li>Day Trips</li>
<li>Food+Drink
<ul>
<li>Dining Picks</li>
<li>Food Cart Fare </li>
<li>Beer, Wine & Spirits</li>
<li>Café Culture</li>
</ul>
</li>
<li>To Do
<ul>
<li>Shopping</li>
<li>Recreation</li>
<li>Culture
<ul>
<li>Galleries</li>
</ul>
</li>
<li>Family</li>
</ul>
</li>
<li>Events</li>
</ul>
</nav>
this is the css i'm using:
nav ul ul li a::before {
content: "\f0da";
font-family: FontAwesome;
margin-right: 8px;
}
nav {
text-transform:uppercase;
font-family: Oswald,Arial,Helvetica,sans-serif !important;
font-size: 14px;
font-weight: 100 !important;
letter-spacing: 1px!important;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #FF0066;
padding: 2px 0 0 64px;
border-radius: 0px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #FF0066;
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 15px 20px;
color: #fff; text-decoration: none;
}
nav ul ul {
background: #FF0066; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 25px;
color: #fff;
font-family: 'Fira Sans', sans-serif;Important;
font-size: 12px;
}
nav ul ul li a:hover {
background: #AD0548;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
nav ul ul ul li {
width: 275px !important;
}
#media (max-width: 767px) {
#logo a {
background: rgba(0, 0, 0, 0) url("http://discoverportland.net/templates/urbanlife/images/logos/DP_HeadingLogo2.png") no-repeat scroll 0 0 / 100% auto;
height: 60px;
margin: 0 !important;
width: 60px !important;
}
#menu-icon {
display:inline-block;
}
nav ul, nav:active ul {
display: none;
position: absolute;
right: 20px;
top: 60px;
width: 50%;
border-radius: 4px 0 4px 4px;
}
nav li {
text-align: center;
width: 100%;
padding: 10px 0;
margin: 0;
}
nav:hover #md {
display: inline-block;
}
}
I have noticed my nav bar is transparent and I would like it to not be. I have no previous opacity/transparency set that would cause it to be inheriting the property. I would like to make my nav bar non transparent.
Here is the CSS:
nav {
margin: 20px auto;
text-align: center;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
font-size: 25px;
background: white;
padding: 0px;
border-radius: 10px;
border-style: solid;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: black;
}
nav ul li:hover a {
opacity: 1;
color: white;
}
nav ul li a {
display: block;
padding: 15px 20px;
color: black;
text-decoration: none;
}
nav ul ul {
background: #000000;
border-radius: 0px 0px 10px 10px;
padding: 0;
position: absolute;
top: 100%;
}
nav ul ul li {
float: none;
}
nav ul ul li a {
padding: 15px 20px;
}
nav ul ul li a:hover {
background: #2E2E2E;
border-radius: 10px;
}
#welcome_paragraph {
position: relative;
top: 50px;
width: 500px;
margin: auto;
}
Here is the corresponding HTML:
<nav>
<ul>
<li>Information
<ul>
<li>Getting Started?</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</li>
<li>Starter Kits</li>
<li>Rebuildables
<ul>
<li>Genesis</li>
<li>Dripper</li>
<li>Silica/Cotton</li>
</ul>
</li>
<li>Mods
<ul>
<li>Mechanical</li>
<li>Variable Voltage</li>
</ul>
</li>
<li>Accessories</li>
</ul>
</nav>
<p id="welcome_paragraph">
Welcome, blah blah (this text shows through the nav bar)<br />
</p>
HTML
<nav>
<ul>
<li>Information
<ul>
<li>Getting Started?
</li>
<li>About Us
</li>
<li>Contact
</li>
</ul>
</li>
<li>Starter Kits
</li>
<li>Rebuildables
<ul>
<li>Genesis
</li>
<li>Dripper
</li>
<li>Silica/Cotton
</li>
</ul>
</li>
<li>Mods
<ul>
<li>Mechanical
</li>
<li>Variable Voltage
</li>
</ul>
</li>
<li>Accessories
</li>
</ul>
</nav>
<p id="welcome_paragraph">Welcome, blah blah (this text shows through the nav bar)
<br />
</p>
CSS
nav {
margin: 20px auto;
text-align: center;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
font-size: 25px;
background: white;
padding: 0px;
border-radius: 10px;
border-style: solid;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: black;
position:relative;
z-index:1;
}
nav ul li:hover a {
color: white;
position:relative;
z-index:1;
}
nav ul li a {
display: block;
padding: 15px 20px;
color: black;
text-decoration: none;
}
nav ul ul {
background: #000000;
border-radius: 0px 0px 10px 10px;
padding: 0;
position: absolute;
top: 100%;
}
nav ul ul li {
float: none;
}
nav ul ul li a {
padding: 15px 20px;
}
nav ul ul li a:hover {
background: #2E2E2E;
border-radius: 10px;
}
#welcome_paragraph {
position: relative;
top: 50px;
width: 500px;
margin: auto;
color:white;
}
body
{
background-color:blue;
}
Updated CSS of yours
nav ul li:hover {
background: black;
position:relative;
z-index:1;
}
nav ul li:hover a {
color: white;
position:relative;
z-index:1;
}
Updated Fiddle
Have you tried;
nav {
background: white;
}
Elements are transparent unless you set a background on them or its inherited.
EDIT: If this doesn't help set up a fiddle for us jsfiddle.net.
In your css
nav ul {
font-size: 25px;
background: white;
padding: 0px;
border-radius: 10px;
border-style: solid;
list-style: none;
position: relative;
display: inline-table;
}
background is white.
If you change background to other colour may be your problem will go off. Hope it will help
Cheers !!
I guess the answer is simple, but still, I cannot figure out how to make my second level menu viewed as an inline-block - from this:
to this:
So what I need is an inline block-listing + text aligned to the center.
Thank you very much for your help.
HTML:
<ul id="menu">
<li>Home</li>
<li>About Us
<ul>
<li>The Team</li>
<li>History</li>
<li>Vision</li>
</ul>
</li>
<li>Products
<ul>
<li>Cozy Couch</li>
<li>Great Table</li>
<li>Small Chair</li>
<li>Shiny Shelf</li>
<li>Invisible Nothing</li>
</ul>
</li>
<li>Contact
<ul>
<li>Online</li>
<li>Right Here</li>
<li>Somewhere Else</li>
</ul>
</li>
CSS:
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left:1px;
white-space: nowrap;
}
ul li a:hover {
background: #BBBBBB;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a {
background: #3b3b3b;
}
li:hover li a:hover {
background: #CCC;
}
add this to your css
ul li {
display: block;
float: left;
}
li:hover ul {
display: block;
position: absolute;
left:0px;
}
li:hover li {
float: left;
font-size: 11px;
}
Demo