I'm trying to keep the menu
on top, but when I hover over one menu, the others should not overlap. How can I achieve this?
Thanks for any help!
Before:
https://i.sstatic.net/esBw6.png
After:
https://i.sstatic.net/slW1n.png
Expected:
https://i.sstatic.net/L0glQ.png
My Code:
var ul = document.querySelector('.nav');
var lis = ul.children;
console.log(lis);
for (var i = 0; i < lis.length; i++) {
lis[i].onmouseover = function() {
this.children[1].style.display = 'block';
}
lis[i].onmouseout = function() {
this.children[1].style.display = 'none';
}
}
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
a {
text-decoration: none;
color: black;
text-align: center;
}
.nav {
position: relative;
width: 300px;
margin: 0 auto;
}
.nav>li {
display: inline-block;
width: 80px;
border: 1px solid blue;
}
.nav>li>a {
display: inline-block;
width: 100%;
padding: 5px 0;
border: 1px solid rgb(245, 108, 172);
}
.nav>li>a:hover {
background-color: #eee;
color: #ff8500;
}
.box {
display: none;
text-align: center;
border: 1px solid red;
}
.box ul li {
border: 1px solid rgb(173, 236, 25);
}
.box ul li a {
display: inline-block;
padding: 5px 34px;
border: 1px solid red;
}
.box ul li a:hover {
background-color: #f1b97c;
color: white;
}
<ul class=nav>
<li>
<a href="#">menu</a>
<div class="box">
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
</ul>
</div>
</li>
<li>
<a href="#">menu</a>
<div class="box">
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
</ul>
</div>
</li>
</ul>