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/
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've read all the questions concerning centering submenus. But I don't get my problem solved.
I have a simple navigation bar with 2 submenus.
You can find it here: Fiddle.
ul#nav, ul#sub1, ul#sub2 {
list-style-type: none;
}
ul#nav {
position: relative;
}
ul#nav li {
width: 125px;
text-align: center;
float: left;
margin-right: 4px;
}
ul#nav a {
text-decoration: none;
display: block;
width: 125px;
height: 25px;
line-height: 25px;
background-color: #FFF;
border: 1px solid #CCC;
border-radius: 5px;
color: #000;
}
ul#sub1 a, ul#sub2 a {
margin-top: 4px;
}
ul#nav li:hover > a {
background-color: #6E6E6E;
color: #FFF;
}
ul#nav li:hover a:hover {
background-color: #E2E2E2;
color: #000;
}
ul#sub1, ul#sub2 {
display: none;
position: absolute;
left: 0px;
}
ul#nav li:hover ul#sub1 {
display: block;
}
ul#sub1 li:hover ul#sub2 {
display: block;
}
<nav>
<ul id="nav">
<li>Reisen
<ul id="sub1">
<li>Europa</li>
<li>Amerika</li>
<li>Asien
<ul id="sub2">
<li>Thailand</li>
<li>Bhutan</li>
<li>China</li>
<li>Vietnam</li>
<li>Japan</li>
</ul>
</li>
<li>Afrika</li>
<li>Australien</li>
</ul>
</li>
<li>Magazin</li>
<li>Karriere
<ul id="sub1">
<li>Thema 1</li>
<li>Thema 2</li>
<li>Thema 3</li>
</ul>
</li>
<li>Kontakt</li>
</ul>
</nav>
I want the submenu centered. When I hover over "Reisen" the submenu gets the same width like the main menu.
When I hover over "Karriere", I want the submenu centered under "Karriere" and not positioned left under "Reisen".
I was thinking of a span-element to the button "Karriere" but I couldn't solve it.
Thanks for your help.
I don't really now if this is what you're looking for or not, but maybe something like this?
Note: I made a few changes to your CSS and HTML, mainly changing everything to use classes instead of IDs
JS Fiddle Example
HTML
<nav>
<ul id="nav">
<li>Reisen
<ul class="sub">
<li>Europa</li>
<li>Amerika</li>
<li>Asien
<ul class="sub-second">
<li>Thailand</li>
<li>Bhutan</li>
<li>China</li>
<li>Vietnam</li>
<li>Japan</li>
</ul>
</li>
<li>Afrika</li>
<li>Australien</li>
</ul>
</li>
<li>Magazin</li>
<li>Karriere
<ul class="sub">
<li>Thema 1</li>
<li>Thema 2</li>
<li>Thema 3</li>
</ul>
</li>
<li>Kontakt</li>
</ul>
CSS
ul#nav, ul.sub {
list-style-type: none;
}
ul#nav {
position: relative;
}
ul#nav li {
width: 125px;
text-align: center;
float: left;
margin-right: 4px;
position: relative;
}
ul#nav a {
text-decoration: none;
display: block;
width: 125px;
height: 25px;
line-height: 25px;
background-color: #FFF;
border: 1px solid #CCC;
border-radius: 5px;
color: #000;
}
ul.sub a {
margin-top: 4px;
}
ul#nav li:hover > a {
background-color: #6E6E6E;
color: #FFF;
}
ul#nav li:hover a:hover {
background-color: #E2E2E2;
color: #000;
}
ul.sub {
display: none;
position: absolute;
left: 0px;
padding-left: 0;
}
ul.sub-second {
display: none;
list-style: none;
left:100px;
top: 0;
position: absolute;
}
ul#nav li:hover ul.sub {
display: block;
}
ul#nav li:hover ul.sub li:hover ul.sub-second {
display:block;
}
}
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/
I have dropdown menu (css only)
JSFIDDLE:
>>> jsfiddle <<<
HTML:
<div class="menu">
<ul>
<li>Home</li>
<li>Tutorials
<ul>
<li>Photoshop</li>
<li>Illustrator</li>
<li>Web Design
<ul>
<li>HTML
<ul>
<li>HTML 4 and less
<ul>
<li>TEST 1</li>
<li>TEST 2</li>
<li>TEST 3</li>
</ul>
</li>
<li>HTML 5</li>
</ul>
</li>
<li>CSS</li>
</ul>
</li>
</ul>
</li>
<li>Articles
<ul>
<li>Web Design</li>
<li>User Experience</li>
</ul>
</li>
<li>Inspiration</li>
</ul>
</div>
CSS:
.menu {
margin: 100px auto;
text-align: center;
}
.menu ul ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
white-space:nowrap;
}
.menu ul {
background: #efefef;
padding: 0;
list-style: none;
position: relative;
display: inline-table;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
}
.menu ul li:hover {
background: blue;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
display: block;
padding: 10px;
color: #757575;
text-decoration: none;
}
.menu ul ul {
background: green;
padding: 0;
position: absolute;
top: 100%;
}
.menu ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid yellow;
position: relative;
}
.menu ul ul li a {
padding: 10px;
color: #fff;
display: block;
}
.menu ul ul li a:hover {
background: red;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top:0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid pink;
position: relative;
}
.menu ul ul ul li a {
padding: 10px;
color: #fff;
display: block;
}
.menu ul ul ul li a:hover {
background: red;
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
top:0;
}
As you see at last submenu, they are not as upper menus. They wrap text and shrink (minimal width).
Q:
How to make them equal (same width as parent) and no text wrap ?
How to simplify this menu (parent, children, ul > li etc.) so I don't need to make new style for each new sub-menu
Thank you in advance.
Try this - this works great on Chrome:
* { white-space: nowrap; box-sizing: border-box; }
.menu {
margin: 100px auto;
text-align: center;
}
/* ULs */
.menu ul {
padding: 0;
position: absolute;
display: none;
background: green;
top: 0;
position: absolute;
list-style: none;
}
.menu > ul {
background: #efefef;
position: relative;
display: inline-table;
}
.menu > ul > li > ul {
top: 100%;
}
.menu li:hover > ul {
display: block;
}
.menu ul ul ul {
left: 100%;
border-left: 1px solid white;
top: -1px;
}
/*LIs*/
.menu li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid yellow;
position: relative;
}
.menu > ul > li {
float: left !important;
border: none;
}
.menu ul li:hover {
background: blue;
}
/* As */
.menu a {
display: block;
padding: 10px;
color: #757575;
text-decoration: none;
}
.menu li:hover a {
color: #fff;
}
.menu ul ul a:hover {
background: red;
}
Also, consider this isn't a good practice (User-experience-wise) to have so many sub menus. You should attempt to re-design your UI to match the usage of your website in a way that won't make the user frustrated.
I need to modify this pure css dropdown menu to be a dropup. Saw a similar post, but can't seem to modify mine. Here is the css code being used for the dropdown, which is working as expected. I tried using bottom: 100% within ul.drop li.hover, ul.drop li:hover {, but that didn't work. Any suggestions.
HTML
<body>
<ul id="nav" class="drop">
<li>Home</li>
<li>Portfolio
<ul>
<li>Horses
<ul>
<li>Horses 1
<li>Horses 2
<li>Horses 3
</ul>
</li>
<li>Dogs</li>
<li>People</li>
<li>Stills</li>
</ul>
</li>
<li>Order</li>
<li>Contact Me
</li>
</ul>
</li>
</ul>
CSS
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
width: 130px;
text-align: center;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 0px solid #ffffff;
padding: 0px 0px 0px 0px;
background: transparent;
# margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: transparent;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
width: 160px;
text-align: left;
}
li:hover a { background: transparent; }
li:hover li a:hover {
background: #3ba110;
}
ul.drop a {
display:block; color: #fff; font-family: Verdana; font-size: 14px; text-decoration: none;
}
ul.drop, ul.drop li, ul.drop ul {
list-style: none; margin: 0; padding: 0; border: 1px solid #fff; background: #1302CB; color: #fff;
}
ul.drop {
position: relative; z-index: 597; float: left;
}
ul.drop li {
float: left; line-height: 1.3em; vertical-align: middle; zoom: 1; padding: 5px 10px;
}
ul.drop li.hover, ul.drop li:hover {
position: relative; z-index: 599; cursor: default; background: #3ba110;
}
ul.drop ul {
visibility: hidden; position: absolute; bottom: 100%; left: 0; z-index: 598; width: 160px; background: #cccccc; border: 1px solid #fff;
}
ul.drop ul li {
float: none;
}
ul.drop ul ul {
top: -2px; left: 100%;
}
ul.drop li:hover > ul {
visibility: visible
}
I didn''t use your CSS because I am not sure what is going on without HTML. Anyways I created a basic demo of what I think you are trying to accomplish.
http://jsfiddle.net/krishollenbeck/JgWEL/45/
HTML
<div class="page">
<ul>
<li class="navlink">
MENU ITEM:
<ul class="dropmenu">
<li>Link One</li>
<li>Link Two</li>
<li>Link Three</li>
</ul>
</li>
</ul>
</div>
CSS
.page {
width:200px;
height:100px;
position:fixed;
top:50%;
bottom:50%;
}
.dropmenu {
display:none;
border:1px solid #CCC;
background-color:#eee;
width:150px;
padding:5px;
position:absolute;
top:-70px;
}
.navlink {
background-color:#000;
padding:5px;
}
.navlink > a {color:#FFF;}
.navlink:hover > .dropmenu {display:block;}