I don't understand why the menu won't highlight on current page? on .menu ul li a:hover, .active {color: #788d35} If I put "background-color" instead of "color"it will work. How do I highlight just the text if current page is active?
HTML:
<section class="menu">
<ul>
<li><a class="active" href="home.html"> HOME </a></li>
<li> PORTFOLIO
<ul>
<li> illustrations </li>
<li> portraits </li>
<li> environments </li>
<li> sketches </li>
</ul>
</li>
<li> STORE
<ul>
<li> society6 </li>
<li> redbubble </li>
</ul>
</li>
<li> CONTACT </li>
<li> ABOUT </li>
</ul>
</section>
CSS:
.menu {
height: 29px;
width: 100%;
/*background:orange;*/
}
.menu ul {
width: auto;
list-style-type: none;
font-family: "calibri", "arial";
}
.menu ul li {
position: relative;
display: inline;
float: left;
width: auto;
border-right: 2px solid purple;
margin-left: 10px;
line-height: 12px;
}
.menu ul li:last-child {
border: none;
}
/*removes border after 'about'*/
.menu ul li a {
display: block;
padding: 3px;
color: #854288;
text-decoration: none;
font-size: 20px;
font-weight: strong;
padding-right: 25px;
}
.menu ul li a:hover,
.active {
color: #788d35
/* <-- if I put "background-color" instead of "color" it will work. How do I highlight just the text if current page is active? */
}
.menu ul li ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
position: absolute;
top: 22px;
float: left;
text-align: left;
z-index: 1000;
background-color: white;
}
.menu ul li ul li {
position: relative;
max-width: 140px;
min-width: 140px;
width: 100%;
border: none;
margin-left: -40px;
}
.menu ul li ul li a {
padding: 4px;
margin-left: 1px;
}
Your .active selector is being overruled by the .menu ul li a selector. So you can either change .active selector to .menu ul li a.active or change the color property color: #788d35; to color: #788d35 !important;
See: http://jsfiddle.net/5mpjj/
For more information: http://hungred.com/useful-information/css-priority-order-tips-tricks/
Related
The submenu is not working correctly. It should appears when hover on specific item, but its appearing when hover any item
HTML
<div class="sty">
<ul class="met_clean_list">
<li>Link 01</li>
<ul>
<li><b>Sublink 01</b></li>
<li><b>Sublink 02</b></li>
</ul>
<li>Link 02</li>
<li>Link 03</li>
</ul>
</div>
CSS
.sty {
background:#aaa;
float:left;
width:600px;
}
.sty ul li {
list-style:none;
position:relative;
padding:25px 10px;
float:left;
}
.sty ul ul{
display:none;
}
.met_clean_list:hover ul {
display:block;
background:red;
}
https://jsfiddle.net/59opc6tj/119/
That's because the hover rule you specified doesn't do what you wish it will do.
You have written: If I hover on .met_clean_list, make all uls within it displayed.
What you wanted to write: If I hover on one of the lis, make the following ul visible.
Thus, you should write .met_clean_list li:hover + ul
.sty {
background: #aaa;
float: left;
width: 600px;
}
.sty ul li {
list-style: none;
position: relative;
padding: 25px 10px;
float: left;
}
.sty ul ul {
display: none;
}
.met_clean_list li:hover + ul {
display: block;
background: red;
}
.sty ul ul:hover {
display: block;
}
<div class="sty">
<ul class="met_clean_list">
<li>Link 01</li>
<ul>
<li><b>Sublink 01</b></li>
<li><b>Sublink 02</b></li>
</ul>
<li>Link 02</li>
<li>Link 03</li>
</ul>
</div>
Notice that I also added:
.sty ul ul:hover {
display: block;
}
So the dropdown won't disappear when you hover on it.
I hope this code will be useful for you
Html:
<ul>
<li>Home</li>
<li>Blog</li>
<li class="dropdown">
Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</ul>
css:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
demo:
https://jsfiddle.net/faridvatani/54qypuds/
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 am attempting a 2 tier drop down menu. I believe I have everything in place but am not getting the drop down. also the :: after is showing pink in notepad ++. is that correct? Ultimately im trying to achieve 5 horizontal menus with the final actually having a vertical 4 drop down nav menu.
</header>
<nav id="nav_menu">
<ul>
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Get Tickets</li>
<li class="lastitem">About Us
<ul>
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
</nav>
AND THEN THE CSS BELOW. I am confident that the html is correct I believe my trouble is in the CSS..
#nav_menu ul{
list-style-type: none;
position: realative;}
#nav_menu ul li {float: left;}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li{float: none;}
#nav_menu ul li:hover > ul{
display: block; }
#nav_menu > ul::after{
content: "";
display: block;
clear: both;}
#nav_menu ul li a {
text-align: center;
display: block;
width: 160px;
padding: 1em 0;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;}
#nav_menu ul li a.lastitem{border-right:none;}
#nav_menu ul li a.current {color: yellow;}
I did some cleanup in your code and the main problem was the typo in position: relative; on the #nav_menu ul element. Therefore the dropdown was out of the visible screen. See the working example below.
#nav_menu ul{
list-style-type: none;
position: relative;
}
#nav_menu ul li {
float: left;
}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li{
float: none;
}
#nav_menu ul li:hover > ul {
display: block;
}
#nav_menu > ul::after{
content: "";
display: block;
clear: both;
}
#nav_menu ul li a {
text-align: center;
display: block;
width: 160px;
padding: 1em 0;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
}
#nav_menu ul li a.lastitem{
border-right:none;
}
#nav_menu ul li a.current {
color: yellow;
}
<nav id="nav_menu">
<ul>
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Get Tickets</li>
<li class="lastitem">About Us
<ul>
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
</nav>
Here's the site I'm working on: http://argumentinamerica.com/
The menu goes like this:
<div id="menu">
<ul id="menu">
<li><span></span>Home</li>
<li class='has-sub'><span></span>Units
<ul>
<li class='has-sub'>Unit 1</li>
<ul>
<li>Read About It</li>
<li>Write About It</li>
<li>Hear About It</li>
<li>Speak About It</li>
<li>Read About It</li>
<li>Write About It</li>
</ul>
<li class='has-sub'>Unit 2</li>
<li class='has-sub'>Unit 3</li>
<li class='has-sub'>Unit 4</li>
<li class='has-sub'>Unit 5</li>
</ul>
<li><span></span>Teacher Center</li>
<li><span></span>About</li>
<li><span></span>Give 1</li>
</ul>
</div>
And the css is like this:
#menu {
margin: 0; padding: 2px 0px 2px 0px;
list-style-type: none;
height: 2.4em;
}
#menu ul, #menu li, #menu span, #menu a {
margin: 0;
padding: 0;
position: relative;
}
#menu li {
float: left;
width: 20%;
}
#menu a {
display: block;
margin: 1px;
height: 2.4em;
font-size: 10px;
line-height: 2.4em;
text-decoration: none;
text-transform: uppercase;
text-align: center;
background: #ffcc66;
color: #996600;
}
#menu span {
position: absolute; top: 8px; left: 8px;
width: 8px; height: 8px;
background: #ff9933;
}
#menu a:hover {
background: #cc3300;
color: #ffcc66;
}
#menu ul{
list-style-type: none;
}
#menu .has-sub {
z-index: 1;
}
#menu .has-sub:hover > ul {
display: list-item;
}
#menu .has-sub ul {
display: none;
position: absolute;
left:0;
}
#menu .has-sub ul li {
*margin-bottom: -1px;
position: relative;
width: 100%;
height: 2.6em;
line-height: 2.4em;
}
#menu .has-sub ul li a {
background: #ff9944;
font-size: 11px;
color: ffcc66;
}
#menu .has-sub ul li:hover a {
background: #ff6633;
color: 993300;
}
#menu .has-sub {
z-index: 1;
}
#menu .has-sub:hover > ul {
display: list-item;
}
#menu .has-sub .has-sub ul {
display: none;
position: absolute;
left:0;
}
#menu .has-sub .has-sub ul {
display: none;
position: absolute;
left:0;
}
#menu .has-sub .has-sub ul li {
*margin-bottom: -1px;
position: relative;
width: 100%;
height: 2.6em;
line-height: 2.4em;
}
#menu .has-sub .has-sub ul li a {
background: #ff9944;
font-size: 11px;
color: ffcc66;
}
#menu .has-sub .has-sub:hover > ul {
display: block;
}
#menu .has-sub .has-sub ul li:hover a {
background: #ff6633;
color: 993300;
}
The third tier is under Units: Unit 1.
I looked at Displaying third tier submenus properly with css only menu and https://stackoverflow.com/questions/13775342/adding-third-tier-to-drop-down-menu and DropDown Menu won't to display on hover and a lot of other questions trying to figure out what's wrong, but I still can't get the third tier to display. I would really appreciate someone taking a look and telling me what I'm missing.
First, the CSS which causes the third tier to appear is not correct:
#menu .has-sub .has-sub:hover > ul {
display: block;
} In this code the '>' targets an ul which is a direct child of a .has-sub:hover element - in your HTML the 3rd tier ul is not a child of the li.has-sub element. You could change the > to a +, which means it targets an ul element directly following the li.has-sub element which for this code causes the third tier to appear. The next problem is that the third tier items appear directly underneath the second tier, so they need to be moved somewhere - see the example code.
http://codepen.io/nztim/pen/GpbqK
Now you need to get the menu to stay visible when you hover over the third tier, but I'll leave that to you, all the best :)
I have created the navigation menu listed below:
<div class="menu">
<ul>
<li>
<a href="index.php" target="_self" >Home</a>
</li>
<li>
<a href="preparation.php" target="_self" >Gallery</a>
<ul>
<li>
Storybooks
</li>
<li>
Preparation
</li>
<li>
Ceremony
</li>
<li>
Personal Shooting
</li>
<li>
First Dance
</li>
<li>
Details
</li>
</ul>
</li>
<li>
<a href="login.php" target="_self" >Customers</a>
</li>
<li>
<a href="about.php" target="_self" >About</a>
</li>
<li>
<a href="contact.php" target="_self" >Contact</a>
</li>
</ul>
</div>
The CSS for this menu at the moment is:
.menu {
margin: 0px;
padding: 0px;
font-family: "Times New Roman";
font-size: 14px;
font-weight: bold;
color: #6D6D6D;
}
.menu ul {
height: 26px;
list-style: none;
margin: 0;
padding: 0;
}
.menu li {
float: left;
padding: 0px;
}
.menu li a {
color: #6D6D6D;
display: block;
font-weight: normal;
line-height: 26px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
}
.menu li a:hover, .menu ul li:hover a {
background: #ca9875 url("menu_images/hover.gif") bottom center no-repeat;
color: #6D6D6D;
text-decoration: none;
}
.menu li ul {
/*background:#333333;*/
/*background: #B32267;*/
background: white;
display: none;
height: auto;
padding: 0px;
margin: 0px;
border: 0px;
position: absolute;
/*width: 225px;*/
width: 135px;
z-index: 200;
/*top:1em;
/*left:0;*/
}
.menu li:hover ul {
display: block;
}
.menu li li {
background: url('menu_images/sub_sep.gif') bottom left no-repeat;
display: block;
float: none;
margin: 0px;
padding: 0px;
/*width: 225px;*/
width: 135px;
}
.menu li:hover li a {
background: none;
}
.menu li ul a {
display: block;
height: 26px;
font-size: 13px;
font-style: normal;
margin: 0px;
padding: 0px 10px 0px 15px;
text-align: left;
}
.menu li ul a:hover, .menu li ul li:hover a {
background: #ca9875 url('menu_images/hover_sub.gif') center left no-repeat;
border: 0px;
color: #ffffff;
text-decoration: none;
}
.menu p {
clear: left;
}
I would like to know if there is a way to add second-level submenu to the category "Storybooks"? What i mean is that I would like to view another submenu in the right while i hover the mouse over the "Storybooks". Is this possible with css?
Appreciate any help, thanks.
I edited your code above to make it work, see http://jsfiddle.net/BVvc6/1/ for the new code.
Note: I added two menu points below Storybooks called Storybook 1 and Storybook 2. CSS is added to the bottom of the existing code (nothing altered above).
EDIT: You should clear up your CSS code a bit, e.g. use CSS selectors like > to match specific DOM levels.