Day # 9: Dropdown Menu
Dropdown menus are a very common functionality for navbars. They allow you to contain elements that can be displayed if the user puts the cursor over that menu. In other words, it’s like a menu within a menu. I tried to achieve this by just using HTML and CSS, since it is a common practice to do that by adding Javascript. The thing is, if we can do something with only HTML and CSS, then that’s a more ideal choice than adding the Javascript component. That way we can make the website more efficient in terms of its loading, since we are not consuming additional features that can make the website slower to load. The key here is to set the display property of those list items within the menu that will dropdown to “none”, when that menu is not hovered. ul li ul.dropdown li {
display: block;
} And then change it to “block” once the user is putting his cursor over the menu. ul li:hover ul.dropdown {
display: block;
} And just like that, in a very simple way, we are able to create a dropdown menu without having to recur to Javascript, which is a language that we can dispose of when it comes to adding more sophisticated features.
Comments
Post a Comment