I'm learning CSS, so I began creating a dropdown menu and I have a question. Here is the structure of my nav:
<nav>
<ul>
<li>style 1
<ul class="sub-menu menu-1">
<li>uno</li>
<li>dos</li>
<li>tres</li>
</ul>
</li>
<li>style 2
<ul class="sub-menu menu-2">
<li>uno</li>
<li>dos</li>
<li>tres</li>
</ul>
</li>
<li>style 3 </li>
<li>style 4 </li>
</ul>
</nav>
Why must each li
from the submenus be positioned absolute, while its parent must be relative in order for the submenu to drop down?
If I ignore that I get the following (it drops down the whole area of nav, not just the submenu):
But if I set submenu's parent a position of relative, and set the submenu's position as absolute, it works:
I want to understand why this happens, how the absolute and relative positions work altogether to make it work.