Estou tentando fazer um dropdown Menu, o problema é que eu gostaria que este menu sobreposse o conteúdo da div. Já tentei usar o position: absolute
, funciona, entretando a div do dropdown Menu explode para fora da div a qual ele está contido.
document.querySelectorAll(".select").forEach((el)=> {
el.addEventListener("click", function (e){
this.classList.toggle("collapsed");
});
});
#submenuUser{
height: calc(100% - 210px);
width: 200px;
float: left;
margin-right: 5px;
border: solid 1px green;
background-color: #515151;
}
#listStyle{
list-style: none;
border-top: solid 1px grey;
padding-left: 0;
margin: 0;
}
#listStyle2{
list-style: none;
padding-left: 0;
margin-top: 5px;
}
#listStyle li{
border-bottom: solid 1px gray;
}
#listStyle li:hover{
background: #555;
}
#listStyle li a{
color: white;
height: 50px;
text-decoration: none;
display: block;
}
.select{
width: 100%;
overflow: hidden;
margin: 0;
color: #ffffff;
position: relative;
height: auto;
max-height: calc(50px * 8); /* max 8 element in list */
transition: 0.2s;
}
.select:before {
content: '';
position: absolute;
background-color: #ffffff;
cursor: pointer;
width: 14px;
height: 14px;
-webkit-transform: rotate(45deg);
top: 15px;
right: 15px;
}
.select:after {
content: '';
position: absolute;
background-color: #4682B4;
cursor: pointer;
width: 14px;
height: 14px;
-webkit-transform: rotate(45deg);
top: 20px;
right: 15px;
}
.collapsed {
max-height: 50px;
transition: 0.2s;
}
.collapsed:before {
content: '';
position: absolute;
background-color: #ffffff;
cursor: pointer;
width: 14px;
height: 14px;
-webkit-transform: rotate(45deg);
top: 10px;
right: 15px;
}
.collapsed:after {
content: '';
position: absolute;
background-color: #4682B4;
cursor: pointer;
width: 14px;
height: 14px;
-webkit-transform: rotate(45deg);
top: 5px;
right: 15px;
}
.option, .shown {
width: 100%;
height: 50px;
line-height: 50px;
cursor: pointer;
background-color: #515151;
}
.shown {
background-color: #4682B4;
font-weight: 400;
}
<div id="submenuUser">
<div class="select collapsed">
<li class="shown">Sub Menu</li>
<li class="option">Teste1</li>
<li class="option">Teste2</li>
<li class="option">Teste3</li>
<li class="option">Teste4</li>
</div>
<ul id="listStyle">
<li><a href="#">Teste1</a></li>
<li><a href="#">Teste2</a></li>
<li><a href="#">Teste3</a></li>
<li><a href="#">Teste4</a></li>
</ul>
</div>
Como eu poderia resolver este problema ?