drop-down menu
by slacr_
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:root {
--nav-color: lime;
--nav-height: 70px;
}
* {
padding: 0;
border: 0;
margin: 0;
box-sizing: border-box;
}
li {
list-style: none;
}
body {
position: relative;
width: 100vw;
height: 100vh;
}
.container {
position: fixed;
display: flex;
left: 50%;
top: 50%;
width: 1000px;
height: var(--nav-height);
transform: translate(-50%, -50%);
}
.nav {
width: 100%;
height: 100%;
display: flex;
}
.nav>li {
flex: 1;
}
.nav>li:not(:first-child) {
margin-left: -1px;
}
.subnav {
display: flex;
flex-direction: column;
align-items: center;
max-height: var(--nav-height);
overflow: hidden;
transition: all cubic-bezier(0.77, 0, 0.175, 1) .4s;
}
.subnav:hover {
max-height: 400px;
}
.subnav>li {
position: relative;
width: 100%;
height: var(--nav-height);
text-align: center;
line-height: var(--nav-height);
background-color: var(--nav-color);
border: 1px solid;
cursor: pointer;
}
.subnav>li:not(:first-child) {
margin-top: -1px;
}
.subnav>li:hover::after {
position: absolute;
left: 0;
top: 0;
content: '';
display: block;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, .6);
}
</style>
</head>
<body>
<div class="container">
<ul class="nav">
<li>
<ul class="subnav">
<li>Orange</li>
<li>Banana</li>
<li>Pear</li>
</ul>
</li>
<li>
<ul class="subnav">
<li>Orange</li>
<li>Banana</li>
<li>Pear</li>
...