I use the pseudo-class:focus-within on my menu to show the sub-menu on click, but it shows it for a second, and then the sub-menu disappears. There is no problem when I use pseudo-class: hover, I just have the problem with focus-within.
li class="has-sub-menu" when I click on it to show the ul class="sub-menu" it get disappear.
Can anybody help me, please?
here are my HTML and CSS codes.
li.has-sub-menu{
position: relative;
margin-right: 10px;
padding-bottom: 5px;
}
ul.sub-menu{
position: absolute;
top:20px ;
box-shadow: 0px 0px 3px 3px #a1a1a1;
border-radius:2%;
border: 1px solid;
display: none;
white-space: nowrap;
min-width: 100px;
}
li.has-sub-menu:focus-within ul.sub-menu{
display: block;
}
.sub-menu li{
border-bottom:1px #a1a1a1 dashed;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 30px;
position: relative;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul>
<li class="has-sub-menu">
<ul class="sub-menu">
<li><a href="">VGA</a></li>
<li><a href="">Power</a></li>
<li><a href="">Case</a></li>
<li><a href="">Network </a></li>
<li><a href="">CPU</a></li>
<li><a href="">CPU FAN</a></li>
</ul><a href="">products</a>
</li>
</ul>
</body>
</html>