Check your rendered html.
The Issue:
The behaviour you are observing is a result of the html not being processed in the manner in which you are expecting.
Most likely because you are trying to open another anchor link within an existing one, e.g: <a href="#">containing link <a href="#">nested link</a></a>
What's occurring in your use-case is most likely what's occurring in the embedded code snippet below:
.navbar {
width: 100%;
height: 30px;
overflow: no-display;
}
#headermenu {
display: none;
}
#amenu:hover #headermenu {
display: block;
}
<nav class="navbar">
<ul id="Header">
<li>
<a id="amenu">aaaa
<div id="headermenu">
<ul>
<li><a>menue yek</a></li>
</ul>
</div>
</a>
</li>
</ul>
</nav>
Rendered Output:
Visible in DOM
<nav class="navbar">
<ul id="Header">
<li>
<a id="amenu">aaaa
</a><div id="headermenu"><a id="amenu">
</a><ul><a id="amenu">
</a><li><a id="amenu"></a><a>menue yek</a></li>
</ul>
</div>
</li>
</ul>
</nav>
You may notice that #headermenu
is no longer a child of #amenu
, so the following selectors #amenu:hover #headermenu
fail as a result.
The Solution:
To rectify the above processing and formatting issues, consider making the dropdown element a sibling to the anchor link - and not nested within it. Then move your id
selector to the containing list item itself (parent li
), e.g:
<nav class="navbar">
<ul id="Header">
<li id="amenu"> <!-- add id attribute to containing element -->
<a>aaaa</a> <!-- close your anchor tag -->
<!-- make the dropdown a sibling of the anchor tag -->
<div id="headermenu">
<ul>
<li><a>menue yek</a></li>
</ul>
</div>
</li>
</ul>
</nav>
Code Snippet Demonstration:
.navbar {
width: 100%;
height: 30px;
overflow: no-display;
}
#headermenu {
display: none;
}
#amenu:hover #headermenu {
display: block;
}
<nav class="navbar">
<ul id="Header">
<li id="amenu"> <!-- add id attribute to containing element -->
<a>aaaa</a> <!-- close your anchor tag -->
<!-- make the dropdown a sibling of the anchor tag -->
<div id="headermenu">
<ul>
<li><a>menue yek</a></li>
</ul>
</div>
</li>
</ul>
</nav>
Alternatively:
You could keep the id
attribute on the nested anchor tag and use the adjacent sibling combinator (+
) instead.
.navbar {
width: 100%;
height: 30px;
overflow: no-display;
}
#headermenu {
display: none;
}
/* use the adjacent sibling combinator (+) */
#amenu:hover + #headermenu {
display: block;
}
<nav class="navbar">
<ul id="Header">
<li>
<a id="amenu">aaaa</a> <!-- close your anchor tag -->
<!-- make the dropdown a sibling of the anchor tag -->
<div id="headermenu">
<ul>
<li><a>menue yek</a></li>
</ul>
</div>
</li>
</ul>
</nav>
More on CSS combinators