Here I have a working nav bar with a drop down menu. However I want two different hover effects on both the main nav bar and a different one for the drop down menu, I already have the main nav bar working with a hover effect by adding the below CSS code.
#nav_bar a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
}
I simply need a way of adding a separate hover effect to the drop down menu
You need to use CSS here this way:
#nav_bar>ul>li>a:hover {
//styles here for main menu hover
}
#nav_bar>ul>li>ul>li>a:hover {
//styles here for dropdown menu hover
}
So your CSS for the main menu hover will become:
#nav_bar>ul>li>a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
}
And you can use the following code to specify CSS for the dropdown menu hover:
#nav_bar>ul>li>ul>li>a:hover {
//styles here for dropdown menu hover
}
#nav_bar {
background-color: #a22b2f;
padding: 10px;
box-shadow: 0px 2px 10px;
}
#nav_bar ul {
text-align: center;
padding-left: 0px;
}
#nav_bar ul li {
display: inline-block;
}
#nav_bar ul li a {
color: white;
font-family: Arial;
text-decoration: none;
font-weight: bold;
padding: 15px;
}
#nav_bar ul li ul {
display: none;
}
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: white;
padding: 10px;
border: 1px solid black;
}
#nav_bar ul li:hover ul li {
display: block;
}
#nav_bar ul li:hover ul li a {
color: black;
}
#nav_bar>ul>li>a:hover {
color: blue;
background: #fff;
}
#nav_bar>ul>li>ul>li>a:hover {
color: red;
background: #000;
}
<div id="nav_bar">
<ul>
<li>HOME
</li>
<li>STATUS
</li>
<li>INFO
</li>
<li>GAMEMODES
<ul>
<li>GAMEMODE - SURVIVAL
</li>
<li>GAMEMODE - PURE-PVP
</li>
<li>GAMEMODE - GAMESWORLD
</li>
</ul>
</li>
<li>RULES
</li>
<li>VOTE
</li>
</ul>
</div>
Related
I'm working on this responsive menu using the code from here:
http://www.sanwebcorner.com/2017/03/multi-level-responsive-dropdown-menu.html
I am attempting to modify the code so that it satisfies all the following conditions:
It does not display a background color on any of the top buttons.
It always has black text in the sub menus.
All sub menus behave exactly the same in the responsive design.
But, I am running into several problems. One of which: two items in the main menu appear twice in the responsive submenu and I don't know why.
I have tried multiple solutions including:
Using additional CSS class selectors.
Every variation of colors in the existing CSS that I can think of.
Every variation of additional CSS class selectors I can think of.
I am very much looking forward to seeing this project fully completed and off my plate. If you could please take a look and identify where I'm going wrong on this code, I would be forever grateful. Thank you so very much.
body {
background-color: #908888;
}
.toggle, [id^=drop] {
display: none;
}
menu {
margin: 0;
padding: 0;
background-color: #5E4C4C;
}
menu:after {
content: "";
display: table;
clear: both;
}
menu ul {
float: left;
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
menu ul li {
margin: 0px;
display: inline-block;
float: left;
}
menu a {
display: block;
padding: 14px 20px;
color: #fff;
font-size: 17px;
text-decoration: none;
}
menu a.new {
display: block;
padding: 14px 20px;
color: #000;
font-size: 17px;
text-decoration: none;
background-color: #ffffff;
}
menu a.new2 {
display: block;
padding: 14px 20px;
color: #ffffff;
font-size: 17px;
text-decoration: none;
background-color: #5E4C4C;
}
menu ul li ul li:hover {
background-color: #f6f4fd;
color: #000000;
}
menu a:hover {
background-color: none;
color: #fff;
}
menu a.new:hover {
background-color: #f6f4fd;
color: #000000;
}
menu a.new2:hover {
background-color: #5E4C4C;
color: #ffffff;
}
menu ul ul {
display: none;
position: absolute;
top: 48px;
}
menu ul li:hover > ul {
color: #000000;
display: inherit;
}
menu ul ul li {
width: 170px;
float: none;
display: list-item;
position: relative;
border-bottom: 0px;
background-color: #ffffff;
color: #000000;
}
menu ul ul ul li {
position: relative;
top: -60px;
left: 170px;
background-color: #ffffff;
color: #000000;
}
li > a:after {
content: ' ▼';
font-size: 11px;
}
li > a:only-child:after {
content: '';
}
#media all and (max-width : 768px) {
menu {
margin: 0;
}
.toggle + a, .menu {
display: none;
}
.toggle {
display: block;
background-color: #5E4C4C;
padding: 14px 20px;
color: #FFF;
font-size: 17px;
text-decoration: none;
border: none;
}
.toggle:hover {
background-color: #DC4E5B;
}
[id^=drop]:checked + ul {
display: block;
}
menu ul li {
display: block;
width: 100%;
}
menu ul ul .toggle, menu ul ul a {
padding: 0 40px;
}
menu ul ul ul a {
padding: 0 80px;
}
menu a:hover, menu ul ul ul a {
background-color: #f6f4fd;
}
menu a.new:hover {
background-color: #f6f4fd;
color: #000000;
}
menu a.new2:hover {
background-color: #5E4C4C;
color: #ffffff;
}
menu ul li ul li .toggle, menu ul ul a, menu ul ul ul a {
padding: 14px 20px;
color: #FFF;
font-size: 17px;
}
menu ul li ul li .toggle, menu ul ul a {
background-color: #BF3441;
}
menu ul ul {
float: none;
position: static;
color: #ffffff;
}
menu ul ul li:hover > ul, menu ul li:hover > ul {
display: none;
}
menu ul ul li {
display: block;
width: 100%;
}
menu ul ul ul li {
position: static;
}
}
#media all and (max-width : 330px) {
menu ul li {
display: block;
width: 94%;
}
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Multilevel Responsive Menu using css</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<menu>
<label for="drop" class="toggle" style="background-color: #BC7A1E;">Menu</label>
<input type="checkbox" id="drop" />
<ul class="menu">
<li><a class="new2" href="#">My Bid</a></li>
<li>
<label for="drop-1" class="toggle">Dashboard ▼</label>
<a class="new2" href="#">Dashboard</a>
<input type="checkbox" id="drop-1"/>
<ul>
<li><a class="new" href="#">Dashboard1</a></li>
<li><a class="new" href="#">Dashboard2</a></li>
<li><a class="new" href="#">Dashboard3</a></li>
</ul>
</li>
<li>
<label for="drop-2" class="toggle">Identity ▼</label>
<a class="new2" href="#">Identity</a>
<input type="checkbox" id="drop-2"/>
<ul>
<li><a class="new" href="#">Identity1</a></li>
<li><a class="new" href="#">Identity2</a></li>
<li>
<label for="drop-3" class="toggle">Identity3 ▼</label>
<a class="new" href="#">Identity3</a>
<input type="checkbox" id="drop-3"/>
<ul>
<li><a class="new" href="#">Identity3.1</a></li>
<li><a class="new" href="#">Identity3.2</a></li>
<li><a class="new" href="#">Identity3.3</a></li>
</ul>
</li>
</ul>
</li>
<li>Change Password</li>
<li>Invalid Bid Report</li>
<li>Rft Upload</li>
<li>Logout</li>
</ul>
</menu>
</body>
</html>
The twice menu problem is because you have media query it changing the display property of this <label for="drop-1" class="toggle">Dashboard ▼</label> tag .
Just remove menu a.new2 { display : block; }. Its on line 58, i think. Remove only the display: block declaration, not the entire rule.
That should solve that duplicate link issue.
I have a dropdown menu that is working well except for one minor bug that I cannot solve.
The first dropdown menu item appears normally. However, the second dropdown menu item is shifted slightly to the right. I am guessing that the margin-right that I set to the link caused the dropdown menu to shift slightly to the right. If that is the case, what can I do to go around the problem?
It's a simple nav menu that sets the position of the dropmenu item to absolute, and is hidden by the parent element's overflow:hidden feature. On hover, the dropdown menu is brought into view with overflow:visible.
The live site is here -> nav menu
CSS
#mainMenu {
position: relative;
}
#mainMenu ul {
list-style: none;
float: right;
background-color: #FFFFFF;
}
#mainMenu ul li {
position: relative;
display: inline;
float: left;
/*padding-right: 1.5em;*/
font-size: 1.2em;
zoom:1;
overflow: hidden;
}
#mainMenu>ul>li {
line-height: 2em;
}
#mainMenu ul li:hover {
overflow: visible;
}
#mainMenu ul li a {
float: left;
text-decoration: none;
color: black;
padding: 0 1em;
}
#mainMenu>ul>li:last-child a {
padding:0.4em 1em 0.4em 1em;
border-radius:4px;
background-color: #00b200;
color: #FFFFFF;
}
#mainMenu ul li a:hover{
text-decoration: none;
color: rgb(42, 160, 239);
}
#mainMenu ul ul{
position: absolute;
top: 2em;
left: 60%;
width: 10em;
margin-left: -3em;
height: auto;
border: solid #CCC;
border-width: 0 1px 1px;
}
#mainMenu ul ul:first-child{
padding-top: 2em;
}
#mainMenu ul ul li,
#mainMenu ul ul a {
display:block;
float:none;
border:0;
box-shadow:none;
text-align:center;
font-size: 1em;
padding: 0.4em;
text-align: left;
}
#mainMenu ul ul li:first-child {
border-top:1px solid rgb(72, 147, 196);
}
#mainMenu ul ul li {
border-top: 1px solid #e9e9e9;
}
#mainMenu a:active,
#mainMenu a:focus,
#mainMenu a:hover {
background:#F2F6FA;
color:#333;
}
HTML
<div id="nav-row">
<h1>
<a href="\">
Corporate Site
<span></span>
</a>
</h1>
<div id="mainMenu">
<ul>
<li>About
<ul>
<li class="company">Company Profile</li><li class="team">
The Team</li><li class="linsux">
Pricing Packages</li>
</ul></li>
<li>Services
<ul>
<li class="webDesign">Websites</li><li class="Emails">
Landing Pages</li><li class="Logos">
Logos</li>
</ul></li>
</li>
<li>Case Studies</li><li>
Blog</li><li>
Contact</li><li>
Free Web Analysis</li>
</ul>
</div>
</div>
It because you use to indent the submenu % of parent width which isn't the same. margin-left: -3em is a constant.
Use, for example:
left: -10px; /* I see the first submenu cca. 10px before the parent LI */
margin-left: 0;
Not sure why you indent by 60% and the move the submenu back using -3em.
try the following :
#mainMenu ul ul {
left: 39% !important;
}
Or
#mainMenu ul ul {
left: 0;
margin-left: 0;
}
I have a question regarding a menu. If I select an li item, I want that selected item to have the same background-color property as the li:hover state and stay so, until I hover and choose another li item.
This is my html:
<div class="submenu-container">
<div class="submenunavYH">
<p>YH Högskola</p>
<div class="submenusettings"></div>
</div>
<div class="submenuYH submenu">
<ul>
<li><a href="utbild.html">
<p>Visual Merchandiser YH</p>
</a></li>
<li><a href="lia.html">
<p>LIA</p>
</a></li>
<li><a href="faq.html">
<p>FAQ</p>
</a></li>
<li><a href="ansok.html">
<p>Ansök här</p>
</a></li>
</ul>
</div>
</div>
and this is my css:
.submenu-container {
display: block;
position: relative;
width: 220px;
background-color: #f3f0ef;
margin: 3% auto 0;
padding: 0;
}
.submenunavYH, .submenunavRetail, .submenunavProjekt{
height: 40px;
text-align: center;
line-height: 2.5em;
color: #ffffff;
}
.submenunavYH{
background-color: #660066;
}
.submenunavRetail{
background-color: #336600;
}
.submenunavProjekt{
background-color: #000000;
}
.submenuYH ul li:hover {
border-left:3px solid #cc66cc;
background-color:rgba(204,102,204,0.1);
}
.submenuRetail ul li:hover {
border-left:3px solid #99CC66;
background-color:rgba(153, 204, 102,0.1);
}
.submenuProjekt ul li:hover {
border-left:3px solid #666666;
background-color:rgba(102, 102, 102,0.1);
}
.submenusettings {
height:20px;
float:right;
width:20px;
margin:10px;
}
.submenu ul {
list-style:none;
margin: 0;
padding: 0;
}
.submenu ul li {
border-top: 1px solid rgba(0,0,0,0.1);
padding: 11px 10px;
box-shadow: inset 0 1px 1px #fff;
text-indent: 10px;
}
.submenu ul li a {
font-size:14px;
color:#a4a3a3;
font-family: 'Strait', sans-serif;
font-size:14px;
text-decoration:none;
text-shadow: 1px 1px 1px #fff;
}
If I for example for a:active have the same attributes as the .submenuYH ul li:hover will it maintain those attributes even after I release the mouse?
code your menu as an unordered list with ids and classes as needed for style and position:
<nav id="menu">
<ul>
<li id="parentLi"><a><span>YH Högskola</span></a>
<ul class="submenu">
<li id="childLi">Visual Merchandiser YH</li>
<li id="siblingLi1">LIA</li>
<li id="siblingLi2">FAQ</li>
</ul>
</li>
</ul>
</nav>
You can use javascript and add classes as needed for highlighting path to selected page.
$(document).ready(function () {
$('#parentLi').addClass('current');
$('#childLi').addClass('selected');
)};
then just create the classes .current and .selected to have the same style as your hover.
You will need to have css selectors styled such as these:
#menu {
}
#menu > ul span {
}
#menu li ul li {
}
#menu li {
}
#menu li ul li:hover {
}
#menu li ul {
}
#menu li ul li {
}
#menu li ul li a {
}
You can see the full effect on this site. as you hover energy efficiency you will see that all of the parents are highlighted as well as the current page
I've got an issue with two clashing color schemes in a nested ul menu. The words are all white and the top menu item links need to go orange on hover (which they do). But then the sub menu items need to stay white for the letters with an orange background (which they do) but change to an blue background on hover and have the links stay white. Unfortunately I can't seem to have one without messing up the other.
Here is the code. How can I get the sub menu links to stay white on hover?
<html>
<head>
<style>
a:link, a:visited {
color: #3e82ef;
}
a:hover, a:active {
color: #de9921;
}
#topBar {
position: absolute;
z-index: 10;
top: 0px;
width: 960px;
text-align: left;
color: #fff;
}
#topBar li {
display: inline-block;
font-size: 18px;
}
#topBar a, #topBar a:link, #topBar a:visited {
font-color: #1047A0;
color: #fff;
}
#topBar a:hover, #topBar a:active {
color: #de9921;
}
ul.dropdown {
list-style: none;
position: relative;
z-index: 10;
margin: 0px;
}
ul.dropdown li {
float: left;
zoom: 1;
background: #000;
margin: 0px;
}
ul.dropdown li a {
display: block;
padding: 10px 18px;
color: #fff;
}
ul.dropdown li:hover {
position: relative;
}
ul.sub_menu li:hover {
background: #2b94c8;
color: #fff;
}
/* here is my attempt to keep the links white, but it isn't working */
ul.sub_menu li a:hover {
color: #fff;
}
</style>
</head>
<body>
<div id="topBar">
<ul class="dropdown">
<li> About </li>
<li> Staff </li>
<li> Capabilities
<ul class="sub_menu">
<li>Materials</li>
<li>Automation</li>
<li>Processing</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
Your other CSS is taking precedence. Add the !important tag.
ul.sub_menu li a:hover {
color: #fff !important;
}
JSFiddle
I have made a dropdown menu with rollover image. The rollover image almost works (Benedict Cumberbatch is meant to turn into an otter) and a submenu to drop down (which at the moment doesn't appear).
What have I done wrong? Here is the JSfiddle
The HTML >>
<ul id="nav">
<li><img src="http://static.tumblr.com/bw1wxme/Lgsmzv53i/rollover-1.jpg">
<ul>
<li>1.2.1.1. Sub-Level-3</li>
<li>1.2.1.2. Sub-Level-3</li>
<li>1.2.1.3. Sub-Level-3</li>
<li>1.2.1.4. Sub-Level-3</li>
</ul>
</li>
The CSS >>
#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
opacity:1;
}
#nav li {
float: left; }
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #069;
}
#nav li a:hover {
color: #c00;
background-color: #fff;
}
#nav ul {
list-style-type:none;
display:none;
}
#nav .about:hover {background-image:url('http://static.tumblr.com/bw1wxme/RjMmzv543/rollover-2.jpg');}
You should add this to your css:
#nav li:hover ul {display:block;}
To show it when hover
Updated JsFiddle