I’m making a simple menu that opens on hover, but it doesn’t work properly. For example, if you move the mouse pointer away from the border of menu item "item2_item", the menu item does not disappear immediately. How to fix it best and is it worth using jQuery?
I’m making a simple menu that opens on hover, but it doesn’t work properly. For example, if you move the mouse pointer away from the border of menu item "item2_item", the menu item does not disappear immediately. How to fix it best and is it worth using jQuery?
nav ul#menu {
background-color: #0073BE;
}
nav ul {
list-style: none;
padding: 0px;
min-width: 10em;
}
nav .parent li:hover {
background-color: orange;
}
nav {
margin: 0 auto;
}
nav ul {
text-align: center;
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 100%;
padding: 8px 4px 8px 4px;
}
nav .parent {
position: relative;
line-height: 30px;
font-size: 150%
}
nav .parent li {
background-color: #E4EFF7;
line-height: 30px;
clear: both;
font-size: 70%;
display: inline-block;
float: left;
max-width: 90%;
background-color: darkorange;
margin: 3px;
border-radius: 23px;
line-height: 120%;
padding: 8px 5px 8px 5px;
}
li.parent {
color: yellow;
cursor: pointer;
}
ul>li,
ul>li>ul>li {
position: relative;
float: left;
padding: 3px 5px;
margin: 10px 5px;
cursor: pointer;
}
ul ul ul li {
float: none;
}
li>ul {
display: none;
}
li:hover>ul {
position: absolute;
display: block;
}
li {
position: absolute;
}
<nav>
<ul id='menu'>
<li id='1' attr='end' href=2 depth='1' class='parent'>
<span style='color:yellow'>item 1</span>
<ul id='1'></ul>
</li>
<li id='2' attr='' depth='1' class='parent'>item 2
<ul id='2'>
<li id='2_1' attr='' depth='2' class='parent'>item2item1
<ul id='21'>
<li id='2_2' attr='end' depth='3' class='parent'>item2_1item
</li>
</ul>
</li>
<li id='22' style="z-index:-1" attr='end' depth='2'>item2item2</li>
</ul>
</ul>
</nav>
2
Answers
Here you add
min-width
toul
.I changedul
‘smin-width
by depth dependсyChange this:
To this:
Additional: