codegurukool.com · Free coding tutorials & online compiler

Home › CSS Tutorial › CSS dropdowns

CSS dropdowns

Show a menu on hover.

Hide the menu, then reveal it with :hover on the parent. Add :focus-within so keyboard users get it too.

Example code

<style>
.d{position:relative;display:inline-block}
.m{display:none;position:absolute;background:#eee;min-width:120px}
.d:hover .m,.d:focus-within .m{display:block}
.m a{display:block;padding:8px}
</style>
<div class='d'><button>Menu</button><div class='m'><a href='#'>One</a><a href='#'>Two</a></div></div>

Run this code in the online editor

← Navigation barsAttribute selectors →