I'm trying to make a mobile menu with the structure of ul > li > ul which each sub ul having its height based of the number of li.
But when entering a sub-sub tiny ul of a big sub ul makes the sub-sub tiny ul overflow vertically which is showing the content of its parent :
How can I prevent the sub-sub tiny ul to be overflow vertically ?
$(document).ready(function(){
let menu = $('nav')
// open submenu
menu.find('a').on('click', function(){
let parent = $(this).parent()
parent.toggleClass('active')
})
// close submenu
menu.find('.back').on('click', function(){
let parent = $(this).parent().parent()
parent.toggleClass('active')
})
})
:root {
font-size: 10px;
}
* {
box-sizing: border-box;
}
nav {
position: fixed;
width: 300px;
box-shadow: 0 0 5px rgba(0, 0, 0, .2);
overflow: hidden;
}
nav a:hover {
color: blue;
}
nav > ul {
height: auto;
}
ul {
list-style: none;
padding-inline-start: 0;
padding: 0 1.5rem;
margin: 0;
width: 100%;
background: #FFF;
}
ul > li:not(:last-child) {
border-bottom: 1px solid #AAA;
}
ul > li > a {
display: flex;
justify-content: space-between;
padding: 1.2rem 1.5rem;
font-size: 1.5rem;
line-height: 1.5em;
font-weight: bold;
text-transform: uppercase;
font-family: sans-serif;
cursor: pointer;
}
ul > li:not(.back) > ul ~ a::after {
content: '►';
}
ul > li > ul {
position: absolute;
top: 0;
left: 0;
transform: translateX(100%);
transition: .3s;
overflow-x: hidden;
z-index: 2;
height: 100%;
}
ul > li.back {
margin: 0 -1.5rem;
border-bottom-width: 0;
z-index: 1;
}
ul > li.back > a {
background: #DDD;
font-size: 1rem;
justify-content: flex-start;
}
ul > li.back > a::before {
content: '◄';
margin-right: .5rem;
}
ul > li.see-all > a {
padding: .5rem 0;
font-size: 1.3rem;
text-align: center;
text-transform: inherit;
justify-content: center;
}
ul > li.active > ul {
transform: translateX(0);
}
ul.dark {
padding: 0;
}
ul.dark > li:not(:last-child) {
border-bottom: 1px solid #FFF;
}
ul.dark > li > a {
background: #AAA;
padding: 1.5rem 3rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav>
<ul>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<a>Sub-sub-category 1</a>
</li>
<li>
<a>Sub-sub-category 2</a>
</li>
</ul>
<a>Sub-category 1</a>
</li>
<li>
<a>Sub-category 2</a>
</li>
<li>
<a>Sub-category 3</a>
</li>
<li>
<a>Sub-category 4</a>
</li>
<li>
<a>Sub-category 5</a>
</li>
</ul>
<a>Category 1</a>
</li>
<li>
<a>Category 2</a>
</li>
<li>
<a>Category 3</a>
</li>
<li class="see-all">
<a>See all products</a>
</li>
</ul>
<a>Products</a>
</li>
<li>
<ul>
<li class="back">
<a>Return</a>
</li>
<li>
<a>Fiesta</a>
</li>
</ul>
<a>Events</a>
</li>
</ul>
<ul class="dark">
<li>
<a>Stores</a>
</li>
<li>
<a>Account</a>
</li>
<li>
<a>Contact</a>
</li>
</ul>
</nav>
Thanks for feeback
Related
So I was trying to make a Super sub-menu and for some reason, the super sub-menu appears when I hover above the main menus, not the sub-menus. and I thought something is wrong with the display: none; but I don't know how to fix it. I already tried to put it with the class it still didn't work and I already double-check the HTML to ensure not typo and none so I'm so confused and stuck right now, PLEASE HELP.
The code :
* {
margin: 0;
padding: 0;
}
body {
background-image: url(photo-1542831371-29b0f74f9713.jpg);
background-size: cover;
}
nav {
/* this is a tag */
height: 60px;
background-color: white;
display:flex;
}
nav a {
font-family: arial, sans-serif;
color: #222;
font-size: 18px;
line-height: 55px;
padding: 2.3px 14px;
text-decoration: none;
text-align: center;
display: block;
}
nav form {
max-width: 100%;
height: 60px;
}
nav ul {
display:flex;
list-style: none;
}
nav li:hover>a {
background: rgb(224, 224, 224);
cursor: pointer;
}
nav ul li ul {
display: none;
position: absolute;
background-color: rgba(255, 238, 238, 0.89);
backdrop-filter: blur(5px);
border-radius: 0px 0px 4px 4px;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li ul {
display: none;
position: absolute;
top: 0;
right: 0;
-ms-transform: translate(100%,0);
-webkit-transform: translate(100%,0);
transform:translate(100%,0);
list-style: none;
}
.subMenu li:hover>.SuperSubMenu{
display: block;
}
<!DOCTYPE html>
<html>
<head>
<title>Wall of nothing</title>
<link rel="stylesheet" type="text/css" href="Style.css">
</head>
<body>
<nav id="navbar">
<form name="" method="" action="BUTTON%20TEST.html">
<input type="image" name="IB1" src="gradient-coding-logo-template_23-2148809439.jpg" width="70" height="60">
</form>
<ul>
<li>
About
<ul>
<li>
Expectations
</li>
<li>
FAQ
</li>
<li>
Laptop Program
</li>
</ul>
</li>
<li>
Why?
<ul>
<li>
What?
</li>
<li>
Events & Activities
</li>
<li>
Meet The Grads
</li>
</ul>
</li>
<li>
Events
<ul>
<li>
Opportunities
</li>
<li>
asd
</li>
</ul>
</li>
<li>
assd
</li>
<li>
Contact
<ul class="subMenu">
<li>
Numbers
<ul class="SuperSubMenu">
<li>
Person1
</li>
<li>
Person2
</li>
</ul>
</li>
<li>
Fax
</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
It's not working because
nav ul li:hover ul {
display: block;
}
is overwriting
.SuperSubMenu {
display: none;
}
property.
To fix it you can add !important to both css for SuperSubMenu. This isn't probably the best way, but it works.
* {
margin: 0;
padding: 0;
}
body {
background-image: url(photo-1542831371-29b0f74f9713.jpg);
background-size: cover;
}
nav {
/* this is a tag */
height: 60px;
background-color: white;
display:flex;
}
nav a {
font-family: arial, sans-serif;
color: #222;
font-size: 18px;
line-height: 55px;
padding: 2.3px 14px;
text-decoration: none;
text-align: center;
display: block;
}
nav form {
max-width: 100%;
height: 60px;
}
nav ul {
display:flex;
list-style: none;
}
nav li:hover>a {
background: rgb(224, 224, 224);
cursor: pointer;
}
nav ul li ul {
display: none;
position: absolute;
background-color: rgba(255, 238, 238, 0.89);
backdrop-filter: blur(5px);
border-radius: 0px 0px 4px 4px;
}
.SuperSubMenu {
display: none !important;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li ul {
display: none;
position: absolute;
top: 0;
right: 0;
-ms-transform: translate(100%,0);
-webkit-transform: translate(100%,0);
transform:translate(100%,0);
list-style: none;
}
.subMenu li:hover>.SuperSubMenu{
display: block !important;
}
<!DOCTYPE html>
<html>
<head>
<title>Wall of nothing</title>
<link rel="stylesheet" type="text/css" href="Style.css">
</head>
<body>
<nav id="navbar">
<form name="" method="" action="BUTTON%20TEST.html">
<input type="image" name="IB1" src="gradient-coding-logo-template_23-2148809439.jpg" width="70" height="60">
</form>
<ul>
<li>
About
<ul>
<li>
Expectations
</li>
<li>
FAQ
</li>
<li>
Laptop Program
</li>
</ul>
</li>
<li>
Why?
<ul>
<li>
What?
</li>
<li>
Events & Activities
</li>
<li>
Meet The Grads
</li>
</ul>
</li>
<li>
Events
<ul>
<li>
Opportunities
</li>
<li>
asd
</li>
</ul>
</li>
<li>
assd
</li>
<li>
Contact
<ul class="subMenu">
<li>
Numbers
<ul class="SuperSubMenu">
<li>
Person1
</li>
<li>
Person2
</li>
</ul>
</li>
<li>
Fax
</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
You need to use direct descendant operators in your third-to-last CSS rule - the one which makes regular sub menus appear when hovering the main menu items. Otherwise this rule will also affect (i.e. make visible) the ul of the SuperSubMenus on hover of the main menu items. So change this selector:
nav ul li:hover ul {
display: block;
}
...to the following:
nav > ul > li:hover > ul {
display: block;
}
* {
margin: 0;
padding: 0;
}
body {
background-image: url(photo-1542831371-29b0f74f9713.jpg);
background-size: cover;
}
nav {
/* this is a tag */
height: 60px;
background-color: white;
display:flex;
}
nav a {
font-family: arial, sans-serif;
color: #222;
font-size: 18px;
line-height: 55px;
padding: 2.3px 14px;
text-decoration: none;
text-align: center;
display: block;
}
nav form {
max-width: 100%;
height: 60px;
}
nav ul {
display:flex;
list-style: none;
}
nav li:hover>a {
background: rgb(224, 224, 224);
cursor: pointer;
}
nav ul li ul {
display: none;
position: absolute;
background-color: rgba(255, 238, 238, 0.89);
backdrop-filter: blur(5px);
border-radius: 0px 0px 4px 4px;
}
nav > ul > li:hover > ul {
display: block;
}
nav ul li ul li ul {
display: none;
position: absolute;
top: 0;
right: 0;
-ms-transform: translate(100%,0);
-webkit-transform: translate(100%,0);
transform:translate(100%,0);
list-style: none;
}
.subMenu li:hover>.SuperSubMenu{
display: block;
}
<!DOCTYPE html>
<html>
<head>
<title>Wall of nothing</title>
<link rel="stylesheet" type="text/css" href="Style.css">
</head>
<body>
<nav id="navbar">
<form name="" method="" action="BUTTON%20TEST.html">
<input type="image" name="IB1" src="gradient-coding-logo-template_23-2148809439.jpg" width="70" height="60">
</form>
<ul>
<li>
About
<ul>
<li>
Expectations
</li>
<li>
FAQ
</li>
<li>
Laptop Program
</li>
</ul>
</li>
<li>
Why?
<ul>
<li>
What?
</li>
<li>
Events & Activities
</li>
<li>
Meet The Grads
</li>
</ul>
</li>
<li>
Events
<ul>
<li>
Opportunities
</li>
<li>
asd
</li>
</ul>
</li>
<li>
assd
</li>
<li>
Contact
<ul class="subMenu">
<li>
Numbers
<ul class="SuperSubMenu">
<li>
Person1
</li>
<li>
Person2
</li>
</ul>
</li>
<li>
Fax
</li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
you can do with simple CSS
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
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;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #3e8e41;}
<div class="dropdown">
<button class="dropbtn">Dropdown Menu</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
when over menu the menu slips in HTML.
Codes and view:
https://codepen.io/anon/pen/XvrJpx
Demo:
.menuu {
position: absolute;
z-index: 1;
}
.menuu ul {
text-align: center;
}
.menuu>ul>li {
list-style: none;
float: left;
margin: 5px;
}
.menuu>ul>li>a {
text-decoration: none;
text-transform: uppercase;
background-color: white;
padding: 5px;
font-weight: 600;
font-size: 16px;
}
.menuu ul li a:hover {
color: white;
background-color: black;
}
.menuu ul li ul {
display: none;
}
.menuu li:hover>ul {
display: block;
}
.menuu ul li ul li a {
text-decoration: none;
}
.menuu>ul>li>ul>li {
list-style: none;
text-align: center;
margin: 5px;
padding: 5px;
}
.icerik {
position: absolute;
top: 75px;
}
<div class="menuu">
<ul>
<li>
Anasayfa
</li>
<li>
c
<ul>
<li>
c1
</li>
</ul>
</li>
<li>
a
</li>
<li>
Programlama
<ul>
<li>
<a>Android</a>
</li>
<li>
Java
</li>
<li>
Php
</li>
<li>
Html
</li>
<li>
Css
</li>
<li>
Javascript
</li>
</ul>
</li>
<li>
Turizm
</li>
<li>
Origami
</li>
<li>
Bebek
<ul>
<li>
Bebeklerin Aylık Gelişimi
</li>
</ul>
</li>
<li>
İletişim
</li>
</ul>
</div>
<div class="icerik">Önceden İçerik Aşağı kayıyordu email de dediğiniz gibi projeme position absolute ekledim kaymıyor. Teşekkür ederim. Şimdi Tek sorun Bebek Bölümü ve C bölümü üstüne gelince yana kayıyorlar ve yanındakini de kaydırıyorlar</div>
Menu C and menu Bebek have submenu. When over menu the menu slips. I doesn’t would slip.
How I can resolve this problem?
I need your help.
All you have to do is remove the browsers default ul styles, as it is adding 40px of padding to the left, and position the sub-menu items absolutely.
In your case, this will work:
ul li ul {
padding: 0;
position: absolute;
}
To make the sub-menu easier to read, I would recommend having a background and some sort of border. eg:
ul li ul {
padding: 0;
position: absolute;
background: white;
border: 1px solid black;
}
Remove > ul from
.menuu li:hover {
display: block;
}
so that menu doesnt slip
Hope this is what you need
.menuu {
position: absolute;
z-index: 1;
}
.menuu ul {
text-align: center;
}
.menuu>ul>li {
list-style: none;
float: left;
margin: 5px;
}
.menuu>ul>li>a {
text-decoration: none;
text-transform: uppercase;
background-color: white;
padding: 5px;
font-weight: 600;
font-size: 16px;
}
.menuu ul li a:hover {
color: white;
background-color: black;
}
.menuu ul li ul {
display: none;
}
.menuu li:hover {
display: block;
}
.menuu ul li ul li a {
text-decoration: none;
}
.menuu>ul>li>ul>li {
list-style: none;
text-align: center;
margin: 5px;
padding: 5px;
}
.icerik {
position: absolute;
top: 75px;
}
<div class="menuu">
<ul>
<li>
Anasayfa
</li>
<li>
c
<ul>
<li>
c1
</li>
</ul>
</li>
<li>
a
</li>
<li>
Programlama
<ul>
<li>
<a>Android</a>
</li>
<li>
Java
</li>
<li>
Php
</li>
<li>
Html
</li>
<li>
Css
</li>
<li>
Javascript
</li>
</ul>
</li>
<li>
Turizm
</li>
<li>
Origami
</li>
<li>
Bebek
<ul>
<li>
Bebeklerin Aylık Gelişimi
</li>
</ul>
</li>
<li>
İletişim
</li>
</ul>
</div>
<div class="icerik">Önceden İçerik Aşağı kayıyordu email de dediğiniz gibi projeme position absolute ekledim kaymıyor. Teşekkür ederim. Şimdi Tek sorun Bebek Bölümü ve C bölümü üstüne gelince yana kayıyorlar ve yanındakini de kaydırıyorlar</div>
I have a hoverable drop down menu where sub links are supposed to be open to the right. This code has remained the same for couple of years now and it's been working. Now I added a new sub link and the code broke.
This is menu's code:
#divMenu, ul, li, li li {
margin: 0;
padding: 0;
}
#divMenu {
width: 150px;
height: 27px;
}
#divMenu ul {
line-height: 50px;
}
#divMenu li {
list-style: none;
position: relative;
background: #cfcfcf;
font-size:20px;
}
#divMenu li li {
list-style: none;
position: relative;
background: #C0C0C0;
left: 148px;
top: -27px;
font-size:12px;
z-index: 999;
}
#divMenu ul li a {
width: 148px;
height: 40px;
display: block;
text-decoration: none;
text-align: center;
font-family: Georgia,'Times New Roman',serif;
color:#000000;
border:1px solid #2d2d2d;
}
#divMenu ul ul {
position: absolute;
visibility: hidden;
top: 27px;
}
#divMenu ul li:hover ul {
visibility: visible;
}
#divMenu li:hover {
background-color: #C0C0C0;
}
#divMenu ul li:hover ul li a:hover {
background-color: #C0C0C0;
}
#divMenu a:hover {
font-weight: none;
}
<div id="divMenu">
<li>Etusivu</li>
<li>Kissala</li>
<li>Maine Coon</li>
<li>Herrat
<ul>
<li><p style="font-size:10px;margin:0px"><a href="hermann.php">Macawi
Mosi Double E´s Xahir</a></p></li>
<li>Vuorensinen Baloo</li>
</ul>
</li>
<li>Ladyt
<ul>
<li>Blackcurrant Sophia Loren</li>
<li>Bloomingtree QQ`Sweetest Taboo</li>
</ul>
</li>
<li>Kastraatit
<ul>
<li>Artsycats Lucy In The Sky</li>
</ul>
</li>
<li>Pennut
<ul>
<li>Varattavissa</li>
<li>Suunnitelmat</li>
<li>Pentuinfo</li>
</ul>
</li>
<li>Pentueet
<ul>
<li>Vintage Star -pentue</li>
<li>Old West -pentue</li>
</ul>
</li>
<li>Linkit</li>
<li>Yhteystiedot</li>
<li><a href="http://users4.smartgb.com/g/g.php?a=s&i=g44-74607-
71">Vieraskirja</a></li>
</ul>
</div>
So I've added one more sub-link there and even if I remove it, the code won't work.
Screen cap: the sub links are shown all the time - not with hovering
You have missed the starting <ul> tag after <div id="divMenu"> . Adding <ul> after <div id="divMenu"> shall fix it for you.
#divMenu, ul, li, li li {
margin: 0;
padding: 0;
}
#divMenu {
width: 150px;
height: 27px;
}
#divMenu ul {
line-height: 50px;
}
#divMenu li {
list-style: none;
position: relative;
background: #cfcfcf;
font-size:20px;
}
#divMenu li li {
list-style: none;
position: relative;
background: #C0C0C0;
left: 148px;
top: -27px;
font-size:12px;
z-index: 999;
}
#divMenu ul li a {
width: 148px;
height: 40px;
display: block;
text-decoration: none;
text-align: center;
font-family: Georgia,'Times New Roman',serif;
color:#000000;
border:1px solid #2d2d2d;
}
#divMenu ul ul {
position: absolute;
visibility: hidden;
top: 27px;
}
#divMenu ul li:hover ul {
visibility: visible;
}
#divMenu li:hover {
background-color: #C0C0C0;
}
#divMenu ul li:hover ul li a:hover {
background-color: #C0C0C0;
}
#divMenu a:hover {
font-weight: none;
}
<div id="divMenu">
<ul>
<li>Etusivu</li>
<li>Kissala</li>
<li>Maine Coon</li>
<li>Herrat
<ul>
<li><p style="font-size:10px;margin:0px"><a href="hermann.php">Macawi
Mosi Double E´s Xahir</a></p></li>
<li>Vuorensinen Baloo</li>
</ul>
</li>
<li>Ladyt
<ul>
<li>Blackcurrant Sophia Loren</li>
<li>Bloomingtree QQ`Sweetest Taboo</li>
</ul>
</li>
<li>Kastraatit
<ul>
<li>Artsycats Lucy In The Sky</li>
</ul>
</li>
<li>Pennut
<ul>
<li>Varattavissa</li>
<li>Suunnitelmat</li>
<li>Pentuinfo</li>
</ul>
</li>
<li>Pentueet
<ul>
<li>Vintage Star -pentue</li>
<li>Old West -pentue</li>
</ul>
</li>
<li>Linkit</li>
<li>Yhteystiedot</li>
<li><a href="http://users4.smartgb.com/g/g.php?a=s&i=g44-74607-
71">Vieraskirja</a></li>
</ul>
</div>
you are just missing opening element ul at first. just change your html code to below :
<div id="divMenu">
<ul>
<li>Etusivu</li>
<li>Kissala</li>
<li>Maine Coon</li>
<li>
Herrat
<ul>
<li>
<p style="font-size:10px;margin:0px">
<a href="hermann.php">
Macawi
Mosi Double E´s Xahir
</a>
</p>
</li>
<li>Vuorensinen Baloo</li>
</ul>
</li>
<li>
Ladyt
<ul>
<li>Blackcurrant Sophia Loren</li>
<li>Bloomingtree QQ`Sweetest Taboo</li>
</ul>
</li>
<li>
Kastraatit
<ul>
<li>Artsycats Lucy In The Sky</li>
</ul>
</li>
<li>
Pennut
<ul>
<li>Varattavissa</li>
<li>Suunnitelmat</li>
<li>Pentuinfo</li>
</ul>
</li>
<li>
Pentueet
<ul>
<li>Vintage Star -pentue</li>
<li>Old West -pentue</li>
</ul>
</li>
<li>Linkit</li>
<li>Yhteystiedot</li>
<li>
<a href="http://users4.smartgb.com/g/g.php?a=s&i=g44-74607-
71">Vieraskirja</a>
</li>
</ul>
</div>
I am wanting to change some items that I have labeled using ids to one single class so that in my CSS I can refer to them with .sortsubmenu rather than #sortsongmenu, #sortartistmenu, etc.
The problem is that when I change one of them from an id to a class, it messes up the formatting. In the picture below, everything about the songsubmenu and artistsubmenu are exactly the same, only songsubmenu is identified using an id and artistsubmenu is identified using a class.
#topbar {
background-color: #222;
}
#topbar_wrapper {
width: 100%;
margin: 0 auto;
text-align: left;
}
#mainmenu {
list-style-type: none;
padding: 0px;
margin: 0px;
position: relative;
min-width: 200px;
}
#mainmenu li {
display: inline-block;
width: 200px;
}
#mainmenu li:hover {
background-color: #333;
}
#mainmenu li a {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#mainmenu li:hover > ul {
display: block;
}
#sortmenu {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
}
#sortmenu > li {
display: block;
position: relative;
}
#sortmenu li a:hover {
color: #699;
}
#sortmenu li:hover ul {
display: inline-block;
}
#sortsongmenu, .sortsubmenu {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-left: 0px;
text-align: right;
top: 0;
left: 100%;
width: 100px;
}
#sortsongmenu li, .sortsubmenu li {
display: inline;
}
#sortsongmenu li a:hover, .sortsubmenu li a:hover {
color: #DB7093;
}
<div id="topbar">
<div id="topbar_wrapper">
<ul id="mainmenu">
<li>Home
</li>
<li>
Search
</li>
<li>
Sort By ▼
<ul id="sortmenu">
<li><a href='#'>Song</a>
<ul id="sortsongmenu">
<li><a href='#'>A to Z</a>
</li>
<li>
<a href='#'>Z to A</a>
</li>
</ul>
</li>
<li>
<a href='#'>Artist</a>
<ul class="sortsubmenu">
<li><a href='#'>A to Z</a>
</li>
<li>
<a href='#'>Z to A</a>
</li>
</ul>
</li>
<li>
<a href='#'>Album</a>
</li>
<li>
<a href='#'>Genre</a>
</li>
<li>
<a href='#'>BPM</a>
</li>
<li>
<a href='#'>Release Date</a>
</li>
</ul>
</li>
<li>
Add Song
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
The #mainmenu li rule is getting in your way. It's not overridden by the class-based selector, as it was by the id-based selector.
Keep that positioning / size to the immediate descendants only, that is, change:
#mainmenu li {
to
#mainmenu > li {
and all is well.
#topbar {
background-color: #222;
}
#topbar_wrapper {
width: 100%;
margin: 0 auto;
text-align: left;
}
#mainmenu {
list-style-type: none;
padding: 0px;
margin: 0px;
position: relative;
min-width: 200px;
}
#mainmenu > li {
display: inline-block;
width: 200px;
}
#mainmenu li:hover {
background-color: #333;
}
#mainmenu li a {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#mainmenu li:hover > ul {
display: block;
}
#sortmenu {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
}
#sortmenu > li {
display: block;
position: relative;
}
#sortmenu li a:hover {
color: #699;
}
#sortmenu li:hover ul {
display: inline-block;
}
#sortsongmenu,
.sortsubmenu {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-left: 0px;
text-align: right;
top: 0;
left: 100%;
width: 100px;
}
#sortsongmenu li,
.sortsubmenu li {
display: inline;
}
#sortsongmenu li a:hover,
.sortsubmenu li a:hover {
color: #DB7093;
}
<div id="topbar">
<div id="topbar_wrapper">
<ul id="mainmenu">
<li>Home
</li>
<li>
Search
</li>
<li>
Sort By ▼
<ul id="sortmenu">
<li><a href='#'>Song</a>
<ul id="sortsongmenu">
<li><a href='#'>A to Z</a>
</li>
<li>
<a href='#'>Z to A</a>
</li>
</ul>
</li>
<li>
<a href='#'>Artist</a>
<ul class="sortsubmenu">
<li><a href='#'>A to Z</a>
</li>
<li>
<a href='#'>Z to A</a>
</li>
</ul>
</li>
<li>
<a href='#'>Album</a>
</li>
<li>
<a href='#'>Genre</a>
</li>
<li>
<a href='#'>BPM</a>
</li>
<li>
<a href='#'>Release Date</a>
</li>
</ul>
</li>
<li>
Add Song
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
I wrote a code using different internet source and I ran into a problem every object that's in the bottom of the menu parts cannot be interacted the menu interferes everything below him where the dropdown falls . the hitbox of the menu seems to included the dropdown even when its not shown
body {
padding: 0;
margin: 0;
font-family: Arial;
font-size: 23px;
}
#nav {
background-color:1a1a1a;
opacity: 0.9;
}
#nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: right;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #333;
}
#nav ul li a, visited {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #333;
border: 0px solid #222;
border-top: 0;
margin-left: -5px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
.left-to-right {
text-align: left;
}
<body dir-"rtl"><div id="nav">
<div id="nav_wrapper">
<div>
<ul <ul dir="RTL">
<li> תרמילים
<ul class="left-to-right">
<!-- <li class="backpacks" id="firstlight-20l"> FirstLight 20L </li>
<li class="backpacks" id="firstlight-30l"> FirstLight 30L </li>
<li class="backpacks" id="firstlight-40l"> FirstLight 40L </li>-->
<li class="backpacks"> rotation180° Professional 38L Deluxe </li>
<li class="backpacks"> rotation180° Horizon 34L </li>
<li class="backpacks"> rotation180° Panorama 22L </li>
<!-- <li class="backpacks" id="rotation180-travel-away"> rotation180° Travel Away 22L </li>-->
<li class="backpacks" id="rotation180-trail"> rotation180° Trail 16L </li>
</ul>
</li>
<li> תיקי מצלמות ספורט
<ul class="left-to-right">
<li>GP 1 kit case
</li>
<li>GP 2 kit case
</li>
</ul>
</li>
<li> אביזרים
<ul class="left-to-right">
<li>r180º Panorama/Horizon Photo Insert
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</body>
Help will be appreciated
edit:
the menu is working but everything below him in the area where the dropdown fals dosent