I have css class which have are both sibling: flex-align
and nav-dropdown
It works fine when I hover the flex-align
, the nav-dropdown
changes.
.flex-align:hover ~ .nav-dropdown {
display: block !important;
}
Problem:
what I want is it only changes when I hover
or focus
the icon
which is a child of flex-align
, that is the only time the nav-dropdown
changes
Thank you
.flex-align {
display: flex;
justify-content: start;
align-items: center;
}
.nav-dropdown {
display: none;
width: auto;
}
.flex-align i:hover ~ .nav-dropdown {
display: block;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="flex-align">
<i class="fa fa-arrow-right dropdown-icon"> </i>
<p>Main test</p>
</div>
<ul class="nav-dropdown">
<li><a href="#">test 1</a></li>
<li><a href="#">test 2</a></li>
<li><a href="#">test 3</a></li>
</ul>
` outside the `.flex-align` using positioning and set `pointer-events: none`. That'll ensure that it does not send hover event to its parent... then set `.flex-align:hover ~ ... {}` rule.
– Salman A May 21 '21 at 08:27