I want to make dropdown menu, but it only works on hover, once I remove mouse from button it hides. BUT, when I get into that menu that it opened, I need it to keep that menu open. So I can get into sections, click on buttons etc…
What make my implementation different is that I use variable to show/hide dropdown menu, not sure how to make it different (my first time making this, trying to learn)
Usually you would use a nested list and when you hover the list parent you will show the nested UL (the dropdown) and in that way the list is always hovered while you navigate the nested element.
In your example your mouse code should go on the div that holds the anchor and the dropdown and not the button itself.
I have no idea why you would use JS instead of css hover (as in the menu you linked to) but the basis is the same.
Heres mostly your code but without the js or injected html so that you can see what structure you need to make this work. I also added the effect you mentioned.
As I said above I would use nested lists for a more semantic structure.
I would also advice against dynamically adding the dropdown content on request as that will make animation harder and makes the navigation pretty useless if js is disabled and of course makes it harder for the site to get indeed in search engines.
well this works, but how can I have greater than “top: 100%;”, and not lose hover ?
This is closest I could get to it have hover. But I have that little of navbar height as well. I need it to be lower (opening menu), but then it won’t hover
But on other hand theworldgames, implements same way, it doesn’t have any more margin between button and dropdown menu
What you can do is that you use padding-top on the sports-drop-down element to push it further down the page but then you need to introduce an inner element and apply all the backgrounds to the inner element instead of the sports drop-down.
This gives the appearance of the menu being pushed down the page but you are still hovering the menu on its padding so it stays in place.
I see you have used a margin-top of 15px instead of top:100%. You can’t do that as it’s a magic number unlike top:100% which will always place the menu at the exact limit of the trigger element.
I’m on a mobile at the moment but will put up a new pen when I get back home.