I need my menu to change color when hovering my mouse over each top menu. The problem is the background color for both Test1 and Sub test1 changes as I hover my mouse. Is there any way to not change the background color of Sub test1 until I hover the mouse over it? See the code at http://jsfiddle.net/r5YCU/22/
Any help will be appreciated. Thanks.
<div id="navbar">
<ul>
<li class="navbutton"><span><a id="button-1"
href="">Shop</a></span>
</li>
<li class="navbutton"> <span>Test1</span>
<ul>
<li><br/><span>Sub test1
</span>
</li>
</ul>
</li>
<li class="navbutton"><span><a id="button-3"
href="#">Test2</a>
</span>
</li>
<li class="navbutton"><span><a id="button-4"
href="#">Test3</a></span>
</li>
<li class="navbutton"><span><a id="button-5"
href="#">Test4</a></span>
</li>
I'd play with css :hover pseudoclass instead javascript events, something like:
li.navbutton:hover {
background-color:#345808 !important;
}
li.navbutton:hover li {
background-color: #5c8727!important;
}
li.navbutton li:hover {
background-color: #345808!important;
}
The complete code is: http://jsfiddle.net/r5YCU/31/
I've adapted the layout a bit to look as similar as possible to the original menu, but only with css code.
These things are related to style and should be done in css...
CSS
.ul{
list-style: none;
}
#navbar a{
text-decoration: none;
}
#main-ul{
background: yellow;
}
.navmenu{
float: left;
background: deeppink;
width: 60px;
height: 25px;
margin-right: 3px;
text-align: center;
line-height: 25px;
box-shadow: 0 0 2px 3px black;
}
.navmenu:hover{
outline: 1px solid white;
margin-top: 1px;
}
.navmenu:hover > #sub-ul{
display: block;
width: 100px;
background: red;
}
#sub-ul{
margin: 0;
padding: 0;
display: none;
}
.submenu{
margin: 0;
padding: 0;
margin-bottom: 2px;
background: black;
color: white;
}
.submenu:hover{
cursor: pointer;
color: black;
background: #585858;
}
HTML
<div id="navbar">
<ul class="ul" id="main-ul">
<li class="navmenu">Test1</li>
<li class="navmenu">Test2
<ul class="ul" id="sub-ul">
<li class="submenu">Test 1</li>
<li class="submenu">Test 2</li>
<li class="submenu">Test 3</li>
<li class="submenu">Test 4</li>
<li class="submenu">Test 5</li>
<li class="submenu">Test 6</li>
<li class="submenu">Test 7</li>
<li class="submenu">Test 8</li>
</ul>
</li>
<li class="navmenu">Test3</li>
<li class="navmenu">Test4</li>
<li class="navmenu">Test5</li>
<li class="navmenu">Test6</li>
<li class="navmenu">Test7</li>
</ul>
</div>
Related
I have an UL that acts as my navigation bar on my web page. currently it is all the way to the left of the screen. I would like it to be centered and have the background color stretch all the way to the left and right, Like below. what would I need to change to stretch the UL across the page like the top example image?
Here is what it looks like currently:
Here is my code:
.parent {
display: block;
position: relative;
float: left;
line-height: 30px;
background-color: #1D3567;
}
.parent a {
margin: 10px;
color: #FFFFFF;
text-decoration: none;
}
.parent:hover>ul {
display: block;
position: absolute;
}
.child {
display: none;
}
.child li {
background-color: #1D3567;
line-height: 30px;
border-bottom: #CCC 1px solid;
border-right: #CCC 1px solid;
width: 100%;
}
.child li a {
color: #FFFFFF;
}
ul {
list-style-type: none;
margin: 0;
padding: 0px;
min-width: 15em;
}
ul ul ul {
left: 100%;
top: 0;
margin-left: 1px;
}
li:hover {
background-color: #95B4CA;
}
.parent li:hover {
background-color: #95B4CA;
}
<ul id="nav_ul">
<li class="parent">Home</li>
<li class="parent">Outlook Web</li>
<li class="parent">Production
<ul class="child">
<li class="parent">Hennig South</li>
<li class="parent">Hennig Enclosure Systems</li>
<li class="parent">Hennig South</li>
<li class="parent">Factory Andon</li>
<li class="parent">Web Docs</li>
</ul>
</li>
<li class="parent">IT
<ul class="child">
<li>Knowledge Base</li>
<li>Submit a Ticket</li>
<li class="parent">Archived Links</li>
</ul>
</li>
<li class="parent">Office Directories
<ul class="child">
<li>Hennig</li>
<li>AME</li>
</ul>
</li>
<li class="parent">Hennig Parts</li>
<li class="parent">Factory Andon</li>
<li class="parent">Business Cards</li>
<li class="parent">Reports
<ul class="child">
<li class="parent">Global Shop<span class="expand">»</span>
<ul class="child">
<li>Inventory Report</li>
<li>Sales Report</li>
<li>Quotes Report</li>
<li>Work Order Report</li>
<li>Part Where Used Report</li>
</ul>
</li>
<li class="parent">Ndustrios<span class="expand">»</span>
</li>
</ul>
</li>
</ul>
Make your ul a flex container in which you align the children centered, and apply the background-color to this element instead of the li children by adding this rule:
#nav_ul {
width: 100%;
display: flex;
justify-content: center;
background-color: #1D3567;
}
.parent {
position: relative;
float: left;
line-height: 30px;
background-color: #1D3567;
}
.parent a {
margin: 10px;
color: #FFFFFF;
text-decoration: none;
}
.parent:hover>ul {
display: block;
position: absolute;
}
.child {
display: none;
}
.child li {
line-height: 30px;
border-bottom: #CCC 1px solid;
border-right: #CCC 1px solid;
width: 100%;
}
.child li a {
color: #FFFFFF;
}
ul {
list-style-type: none;
margin: 0;
padding: 0px;
min-width: 15em;
}
#nav_ul {
width: 100%;
display: flex;
justify-content: center;
background-color: #1D3567;
}
ul ul ul {
left: 100%;
top: 0;
margin-left: 1px;
}
li:hover {
background-color: #95B4CA;
}
.parent li:hover {
background-color: #95B4CA;
}
<ul id="nav_ul">
<li class="parent">Home</li>
<li class="parent">Outlook Web</li>
<li class="parent">Production
<ul class="child">
<li class="parent">Hennig South</li>
<li class="parent">Hennig Enclosure Systems</li>
<li class="parent">Hennig South</li>
<li class="parent">Factory Andon</li>
<li class="parent">Web Docs</li>
</ul>
</li>
<li class="parent">IT
<ul class="child">
<li>Knowledge Base</li>
<li>Submit a Ticket</li>
<li class="parent">Archived Links</li>
</ul>
</li>
<li class="parent">Office Directories
<ul class="child">
<li>Hennig</li>
<li>AME</li>
</ul>
</li>
<li class="parent">Hennig Parts</li>
<li class="parent">Factory Andon</li>
<li class="parent">Business Cards</li>
<li class="parent">Reports
<ul class="child">
<li class="parent">Global Shop<span class="expand">»</span>
<ul class="child">
<li>Inventory Report</li>
<li>Sales Report</li>
<li>Quotes Report</li>
<li>Work Order Report</li>
<li>Part Where Used Report</li>
</ul>
</li>
<li class="parent">Ndustrios<span class="expand">»</span>
</li>
</ul>
</li>
</ul>
I have searched for the answer to this but out of the questions/answers I found none of them worked in my case.
What I have is a "Mega Menu" with links down the left side, when one of the links are hovered with the mouse it expands to the right showing hidden links with images. What I would like to do is have the left side "hoverable" link area expand to be the same size as the right side area that contains the images.
Currently the left side is a fixed height and when I attempted to apply clear: both overflow: hidden as the other answers on questions suggested it broke the layout. I am hoping there is a pure CSS way of doing what I need. I could write it in JS but would prefer not to if its not needed. I have included a codepen that shows what I have currently.
https://codepen.io/anon/pen/wGZjpp?editors=1100
<div class="megaMenuWrapper">
<div class="megaMenuContainer" style="display: block;">
<ul id="menu-main-menu" class="menu">
<div class="background"><span class="megamenu-title">SHOP BY CATEGORY</span>
<li class="category-item" id="menu-item-3">Showers
<ul class="sub-menu right-side">
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-4">
<img src="http://placekitten.com/180/180">Shower Stalls
</li>
<li id="menu-item-8">
<img src="http://placekitten.com/180/180">Shower Bases
</li>
</ul>
</li>
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-5">
<img src="http://placekitten.com/180/180">Shower Walls
</li>
</ul>
</li>
</ul>
</li>
<li class="category-item" id="menu-item-9">Toilets
<ul class="sub-menu right-side">
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-10">
<img src="http://placekitten.com/180/180">Bidets
</li>
<li id="menu-item-11">
<img src="http://placekitten.com/180/180">Portable Toilets
</li>
</ul>
</li>
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-17">
<img src="http://placekitten.com/180/180">Bed Pans
</li>
</ul>
</li>
</ul>
</li>
<li class="category-item" id="menu-item-16">Bathtubs
<ul class="sub-menu right-side">
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-18">
<img src="http://placekitten.com/180/180">Clawfoot
</li>
</ul>
</li>
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-19">
<img src="http://placekitten.com/180/180">Copper
</li>
</ul>
</li>
</ul>
</li>
<li class="category-item" id="menu-item-20">Sinks
<ul class="sub-menu right-side">
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-21">
<img src="http://placekitten.com/180/180">Modern
</li>
</ul>
</li>
</ul>
</li>
<li class="category-item" id="menu-item-25">Bathroom Accessories
<ul class="sub-menu right-side">
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-22">
<img src="http://placekitten.com/180/180">Bathtub Faucets
</li>
<li id="menu-item-27">
<img src="http://placekitten.com/180/180">Shower Curtains
</li>
</ul>
</li>
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-23">
<img src="http://placekitten.com/180/180">Toilet Brushes
</li>
<li id="menu-item-28">
<img src="http://placekitten.com/180/180">Vanities
</li>
</ul>
</li>
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-24">
<img src="http://placekitten.com/180/180">Toilet Seats
</li>
</ul>
</li>
<li class="menu-item">
<ul class="sub-menu">
<li id="menu-item-26">
<img src="http://placekitten.com/180/180">Mirrors
</li>
</ul>
</li>
</ul>
</li>
</div>
</ul>
</div>
</div>
CSS:
body{
background: #ddd;
}
ul#mainnav>li>a:not(.last) {
border-right: 1px solid #fff;
}
ul#mainnav>li>a {
padding: 5px 15px;
margin-top: 20px;
}
.megaMenuWrapper {
position: relative;
margin-top:30px;
}
.megaMenuContainer {
position: absolute;
width: 100%;
/* display: none; */
z-index: 2;
/* height: auto; */
}
ul#menu-main-menu {
width: 100%;
height: 100%;
position: relative;
margin:0;
list-style: none;
}
ul#menu-main-menu .background > li:first-of-type {
margin-top: 5px;
}
.background {
width: 20%;
height: 100%;
background: rgb(255, 255, 255);
border-right: 2px solid #000;
}
.column.menu-item {
padding: 1%;
width: 23%;
}
ul.sub-menu {
list-style: none;
margin: 0;
}
.right-side {
position: absolute;
top: 0;
left: 20%;
height: auto;
right: 0;
width: 80%;
display: none;
}
.right-side li.menu-item {
float: left;
width: 23%;
padding: 1%;
height: 100%;
}
.megamenu-title {
color: #545454;
margin-top: 20px;
display: inline-block;
width: 100%;
margin-left: 20px;
font-weight: bold;
}
li.category-item a{
padding: 5px 0px 5px 20px;
display: block;
}
li.category-item a:hover {
background-color: white;
color: #3C3C3C !important;
text-decoration: none;
}
li.category-item a:hover + ul,
.right-side:hover
{
display: block;
background: rgb(255, 255, 255);
border-left: 1px solid #000;
}
ul#menu-main-menu li.menu-item ul.sub-menu li a {
color: #3c3c3c;
padding: 0;
text-align: center;
}
ul#menu-main-menu li.menu-item ul.sub-menu li a:hover {
background: none;
}
ul#menu-main-menu li.menu-item ul.sub-menu li img {
display: block;
margin: 0 auto;
}
ul#menu-main-menu li a {
color: #4C4C4C;
}
UPDATE:
This is ultimately the jQuery that I have ended up going with. Unless someone answers with a pure CSS solution.
$('.category-item').hover(
function() {
var height = $(this).children('.right-side').outerHeight();
$('.megaMenuContainer').height(height);
},
function() {
$('.megaMenuContainer').css('height', '');
}
);
the idea is the following :
.megaMenuContainer {
height:auto;
}
.category-item {
height:2em;
}
.category-item:hover {
height:3em;
}
in fact if you put the height of the parent equal to auto the height of the child element will follow it.
This is not possible with pure CSS like I wanted with the current structure so I decided to go with the jQuery solution below.
$('.category-item').hover(
function() {
var height = $(this).children('.right-side').outerHeight();
$('.megaMenuContainer').height(height);
},
function() {
$('.megaMenuContainer').css('height', '');
}
);
i am new to HTML and i need to put some sub menus in my side bar.. just like a dropdown but it opens on the right side. and how can i put links on it. thanks
html
<ul>
<li></br>
<a class="active" href="?">HOME</a>
</li>
<li></br>
Manage Users ----> needs the dropdown here
</li>
<li></br>
Manage Employees----> needs the dropdown here
</li>
<li></br>
Search
</li>
<li></br>
Log-Out
</li>
</ul>
here is my css.
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 15%;
background-color: #f1f1f1;
position: fixed;
height: 100%;
overflow: auto;
}
li a {
display: block;
color: #000;
padding: 8px 0 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #4CAF50;
color: white;
}
li a:hover:not(.active) {
background-color: #555;
color: white;
}
...................................................................
<ul>
<li></br>
<a class="active" href="?">HOME</a>
</li>
<li></br>
Manage Users ----> needs the dropdown here
</li>
<li></br>
Manage Employees---->
<ul>
<li> You put the sublists here</li>
<li> Many has you need</li>
</ul>
</li>
<li></br>
Search
</li>
<li></br>
Log-Out
</li>
You don't need the </br> (correct would be <br/>, or <br>for HTML5). I tried to make a simple solution with jQuery. where you simply display or not the content you want.
Hope it is what you were looking for.
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
/*width: 15%;*/
background-color: #f1f1f1;
/*position: fixed;*/
height: 100%;
overflow: auto;
}
li a {
display: block;
color: #000;
padding: 8px 0 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #4CAF50;
color: white;
}
li a:hover:not(.active) {
background-color: #555;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<a class="active" href="#">HOME</a>
</li>
<li>
Manage Users
<ul id="contentUsers" style="display: none;">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li>
Manage Employees
<ul id="contentEmployees" style="display: none;">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li>
Search
</li>
<li>
Log-Out
</li>
</ul>
I have an ul that isn't stacking properly (or is, but not to my desired outcome.)
http://jsfiddle.net/rrrpy1rk/
html:
<ul id="footer_site_map">
<li class="footer_parent">About
<ul class="footer_of_children">
<li class="footer_children">Our Veterinarians
</li>
<li class="footer_children">Our Staff
</li>
</ul>
</li>
<li class="footer_parent">Preventative Medicine
<ul class="footer_of_children">
<li class="footer_children">Puppies
</li>
<li class="footer_children">Kittens
</li>
<li class="footer_children">Adult Care
</li>
<li class="footer_children">Senior Care
</li>
<li class="footer_children">Rabbits
</li>
</ul>
</li>
<li class="footer_parent">Surgical
<ul class="footer_of_children">
<li class="footer_children">Spaying
</li>
<li class="footer_children">Neutering
</li>
<li class="footer_children">Orthopedic Surgery
</li>
<li class="footer_children">Soft Tissue Surgery
</li>
<li class="footer_children">Declawing Cat
</li>
</ul>
</li>
<li class="footer_parent">Medical
<ul class="footer_of_children">
<li class="footer_children"> Complete Medical Assessment
</li>
<li class="footer_children">Cardiology
</li>
<li class="footer_children">Flea Treatment
</li>
<li class="footer_children">Dentistry
</li>
<li class="footer_children">Radiology
</li>
<li class="footer_children">Laboratory
</li>
</ul>
</li>
</ul>
CSS:
#footer_site_map {
position:absolute;
padding:0;
margin:0;
top: 20px;
left: 0;
width:100%;
}
.footer_parent {
position: relative;
width: 180px;
height:20px;
padding: 0 5px;
display: inline-block;
}
.footer_parent a {
color: #FFF;
text-decoration: none;
font-family: MyriadProSemibold;
font-size: 120%;
}
.footer_children {
padding: 5px 0;
width: 200px;
}
.footer_children a {
color: #FFF;
list-style-type: none;
text-decoration: none;
font-family: ralewayregular !important;
font-size: 100%;
}
.footer_of_children {
padding: 0;
margin:0;
}
As seen from the fiddle the parent ul li's are stacking on top of the children ul li's. I need it to go the other way around.
Is there some easy fix, or should I re-structure it.
If you look at the fiddle, you may need to drag the bar to increase the size of the Result.
Addding vertical-align: top; to your .footer_parent fixes the issue:
.footer_parent {
position: relative;
width: 180px;
height: 20px;
padding: 0 5px;
display: inline-block;
vertical-align: top;
}
Ok! So I made this nav bar and it works perfectly in all browsers except IE7.
It is a left side nav and for some reason it collapses in IE7 but every other browser displays it fine.
Here's the html.
<!doctype html>
<html>
<head>
<title>Test</title>
<meta charset="utf-8">
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<ul class="navbar">
<li class="nav_head"><div class="navhd_outline">Products</div></li>
<ul>
<li class="nav_subhead"><div class="navsub_outline">View Categories</div></li>
<li class="nav_subhead"><div class="navsub_outline">Add/Remove</div></li>
</ul>
</li>
<li class="nav_head"><div class="navhd_outline">Email</div></li>
<ul>
<li class="nav_subhead"><div class="navsub_outline">New Blast</div></li>
<li class="nav_subhead"><div class="navsub_outline">View Blast</div></li>
</ul>
</li>
<li class="nav_head"><div class="navhd_outline">Reports</div></li>
<ul>
<li class="nav_subhead"><div class="navsub_outline">By Month</div></li>
<li class="nav_subhead"><div class="navsub_outline">By Type</div></li>
</ul>
</li>
<li class="nav_head"><div class="navhd_outline">Recipes</div></li>
<ul>
<li class="nav_subhead"><div class="navsub_outline">View Recipes</div></li>
<li class="nav_subhead"><div class="navsub_outline">Add/Remove</div></li>
</ul>
</li>
<li class="nav_head"><div class="navhd_outline">Television</div></li>
<ul>
<li class="nav_subhead"><div class="navsub_outline">View List</div></li>
<li class="nav_subhead"><div class="navsub_outline">Add/Remove</div></li>
</ul>
</li>
<li class="nav_head blog_head"><div class="navhd_outline">Blog</div></li>
<ul>
<li class="nav_subhead"><div class="navsub_outline">View Posts</div></li>
<li class="nav_subhead"><div class="navsub_outline">Add/Remove</div></li>
</ul>
</li>
<li class="nav_bottom"> </li>
</ul>
</body>
</html>
And here is the CSS.
.navbar {
float: left;
background-color: #4d89d1;
background-repeat: no-repeat;
background-position: 18px 0px;
top: -25px;
width: 200px;
margin-top: 20px;
margin-left: 30px;
padding-top: 25px;
padding-bottom: 30px;
}
.nav_head {
margin: 0 auto;
padding: 1px;
height: 36px;
list-style: none;
}
.nav_head a {
font-size: 15px;
color: #900606;
}
.nav_head a:hover {
color: #f5bf2b;
}
.navhd_outline {
margin: 1px;
padding-top: 8px;
padding-left: 40px;
padding-bottom: 22px;
border: 1px dashed #f5bf2b;
width: 154px;
height: 2px;
}
.nav_subhead {
padding: 1px;
background-color: #900606;
height: 36px;
list-style: none;
margin-left: 25px;
width: 155px;
text-align: right;
}
.nav_subhead a {
color: #ffffff;
text-decoration: none;
padding-right: 10px;
}
.nav_subhead a:hover {
color: #f5bf2b;
}
.navsub_outline {
margin: 1px;
padding-top: 10px;
padding-left: 20px;
padding-bottom: 20px;
border: 1px dashed #f5bf2b;
width: 131px;
height: 2px;
}
.nav_bottom {
height: 30px;
background-position: 33px 0px;
background-repeat: no-repeat;
}
You still have invalid HTML. The problem repeats through every single <li> so I'm only showing the first one...
<ul class="navbar">
<li class="nav_head">
<div class="navhd_outline">Products</div>
</li> <!-- <<< this one closes the LI item -->
<ul>
<li class="nav_subhead">
<div class="navsub_outline">View Categories</div>
</li>
<li class="nav_subhead">
<div class="navsub_outline">Add/Remove</div>
</li>
</ul>
</li> <!-- <<< this is presently an extra one outside of the LI item -->
...
<li class="nav_bottom"> </li>
</ul>
You still have an extra closing </li> tag for every single <li> item. The inner <ul> needs to be contained inside the <li></li>, where you have it outside along with another </li>. Remove </li> tags as indicated below...
<ul class="navbar">
<li class="nav_head">
<div class="navhd_outline">Products</div>
<ul> <!-- <<< the entire child UL is inside the LI where it belongs -->
<li class="nav_subhead">
<div class="navsub_outline">View Categories</div>
</li>
<li class="nav_subhead">
<div class="navsub_outline">Add/Remove</div>
</li>
</ul>
</li> <!-- <<< this one closes the LI item -->
...
<li class="nav_bottom"> </li>
</ul>
Run your page through the W3C Validator.