I am trying to make a submenu with scrollbars and dropdown list, the ul
inside ‘some other services’ li
is appearing inside the parent block. I’ve tried using position:absolute
which pops ul
out but the list positions with respect to screen. I want it to be with respective to its parent li
position.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
body {
background-color: gray;
}
.menu {
list-style: none;
text-align: center;
padding: 0;
margin: 0;
background-color: white;
}
.menu-item {
font-family: 'Roboto', sans-serif;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 14px;
display: inline-block;
float: left;
background-color: white;
}
.menu-item a {
text-decoration: none;
color: #000000;
display: block;
transition: .3s background-color;
padding: 0 24px;
}
.menu-item a:hover {
background-color: #5c89c7;
color: #FFFFFF;
}
a {
border-bottom: none;
}
.dropdown {
display: none;
background-color: white;
padding: 0;
max-height: 200px;
width: 200px;
max-height: 200px;
overflow: scroll;
}
.menu-item:hover>.dropdown {
display: block;
}
.dropdown-menu-item {
display: block;
line-height: 34px;
background-color: white;
}
.dropdown-menu-item:hover>.dropdown {
display: block;
}
</style>
</head>
<body>
<div class="nav">
<ul class="menu">
<li class="menu-item"><a href="#">HOME</a></li>
<li class="menu-item"><a href="#">ABOUT US</a></li>
<li class="menu-item"><a href="#">SERVICES</a>
<ul class="dropdown">
<li class="dropdown-menu-item"><a href="#">services</a></li>
<li class="dropdown-menu-item"><a href="#">services</a></li>
<li class="dropdown-menu-item"><a href="#">services</a></li>
<li class="dropdown-menu-item"><a href="#">services</a></li>
<li class="dropdown-menu-item"><a href="#">services</a></li>
<li class="dropdown-menu-item"><a href="#">services</a></li>
<li class="dropdown-menu-item"><a href="#">some other services</a>
<ul class="dropdown" style="margin-left:30%; margin-top:-15%; /* position:absolute; */>
<li class=" dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
<li class="dropdown-menu-item "><a href="# ">some other services</a></li>
</ul>
</li>
<li class="dropdown-menu-item "><a href="# ">services</a></li>
<li class="dropdown-menu-item "><a href="# ">services</a></li>
<li class="dropdown-menu-item "><a href="# ">services</a></li>
<li class="dropdown-menu-item "><a href="# ">services</a></li>
<li class="dropdown-menu-item "><a href="# ">services</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>