-2
I am trying to create a dropdown menu, which opens the sub-menu down the button, is working properly until this part. But I would like the menu buttons (DIV’s) to be next to each other. But it’s getting one below the other on the side.
UPDATED
I found my mistake, I was limiting the width of the column to 150px on .dropdown
so I played down the other button, put 100% and stood side by side the buttons.
But every time I pass the mouse first button it throws the second button down from its submenu. And when I hover the mouse on the second button, its submenu opens below the first button.
I’m analyzing my code but I haven’t noticed anything yet. If anyone notices anything causing this.
Follows the code:
CSS:
body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.menu-superior {
background-color: #242424 ;
width: 100%;
padding: 0 ;
}
.dropdown { /* Tamanho do wrapper do dropdown */
width: 100%;
}
.dropdown a { /* Retira sublinhado das âncoras */
text-decoration: none;
}
.dropdown-button { /* Estiliza o botão dropdown */
display: inline-block;
color: white;
font-weight: bolder;
text-align: center;
vertical-align: middle;
background: Green;
padding: 10px 20px;
border-radius: 5px;
}
.dropdown-menu { /* Estiliza o menu dropdown */
width: 150px;
border: 1px solid grey;
border-radius: 5px;
display: none;
}
.menu-item { /* Estiliza cada item do dropdown */
display: block;
width: 100%;
text-align:center;
color: White;
}
/* Mágica do dropdown */
/**
* Seleciona o próximo elemento irmão do .dropdown-button, quando damos foco no dropdown.
* Portanto, o irmão (menu de itens) é visualizado. */
.dropdown-button:hover + .dropdown-menu {
display: block;
}
.dropdown-menu:hover { /* Mantém o menu aberto, quando etiver com mouse sobre algum item*/
display: block;
}
HTML:
<div class="menu-superior">
<div class="dropdown">
<a href="#0" class="dropdown-button">Minhas Contas</a>
<div class="dropdown-menu">
<a href="#1" class="menu-item">Geral</a>
<a href="#2" class="menu-item">Vencidas</a>
<a href="#3" class="menu-item">Comprovantes</a>
</div>
<a href="#0" class="dropdown-button">Configurações</a>
<div class="dropdown-menu">
<a href="#4" class="menu-item">Meus Dados</a>
<a href="#5" class="menu-item">Personalizar</a>
<a href="#6" class="menu-item">Sair</a>
</div>
</div>
</div>
Thank you, little brother, you helped me a lot. I had researched about and assembled this code, but I will take a look at this W3 article to better understand how it works. Hug.
– Gabriel Branger