I have a nav menu with submenus that show when li
elements are hovered.
See below HTML/CSS (hover over Nav 1 to see the issue). The .submenu
element has a max-height
and is set as flex-direction: column
, but I want the pink area to expand when the child items wrap to fit the space? Why is the pink area only covering one 'column'? I want it to cover all of the yellow area... (ie. so that the background of the submenu covers all the children)
.nav {
display: flex;
list-style: none;
}
.nav li {
margin: 10px;
background: aqua;
width: 100px;
}
.menu-item {
position: relative;
}
.submenu {
display: none;
position: absolute;
background-color: pink;
max-height: 300px;
}
.submenu ul {
padding-left: 0;
list-style: none;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.submenu li {
background-color: yellow;
}
.menu-item:hover .submenu {
display: flex;
}
<ul class="nav">
<li class="menu-item">Nav 1
<div class="submenu">
<ul>
<li>Subnav 1</li>
<li>Subnav 2</li>
<li>Subnav 3</li>
<li>Subnav 4</li>
<li>Subnav 5</li>
<li>Subnav 6</li>
<li>Subnav 7</li>
<li>Subnav 8</li>
<li>Subnav 9</li>
<li>Subnav 10</li>
<li>Subnav 11</li>
<li>Subnav 12</li>
<li>Subnav 13</li>
<li>Subnav 14</li>
<li>Subnav 15</li>
</ul>
</div></li>
<li>Nav 2</li>
</ul>