Skip to content

Instantly share code, notes, and snippets.

@EEmmanuel7
Created November 10, 2023 06:37
Show Gist options
  • Save EEmmanuel7/0bbb156d9ee0819cc1170c9cb745c23c to your computer and use it in GitHub Desktop.
Save EEmmanuel7/0bbb156d9ee0819cc1170c9cb745c23c to your computer and use it in GitHub Desktop.
CSS dropdown menu - upward
<div style="height: 300px">
<ul class='menu--main'><li>Home</li>
<li>About</li>
<li>
Portfolio
<ul class='sub-menu'>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog
<ul class='sub-menu'>
<li>Articles</li>
<li>Archive</li>
<li>What's New</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
$light-gray: #f8f9fa;
$menu-bg: $light-gray;
$menu-hover: darken($menu-bg, 9%);
.menu--main {
display: block;
position: absolute;
bottom: 0;
li {
display: inline-block;
position: relative;
cursor: pointer;
padding: 15px 20px;
background-color: $menu-bg;
margin-right: -4px; // get rid of spacing between list items
//transition: all 0.2s;
&:hover {
background-color: $menu-hover;
}
&:hover .sub-menu {
max-height: 300px;
visibility: visible;
bottom: 100%; // align to top of parent element
transition: all 0.4s linear;
}
}
.sub-menu {
display: block;
visibility: hidden;
position: absolute;
//top: 100%; // align to bottom of
left: 0;
box-shadow: none;
max-height: 0;
width: 150px;
overflow: hidden;
li {
display: block;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment