Dropdown problem in the menu

Asked

Viewed 38 times

1

When you display the submenus it is increased the height of the menu, what I want is it to override the menu or anything else that is below.

.menu {
    width: 100%;
    background: #1f1f1f;
    border-bottom: 4px solid #a32c2e;
    font-size: 11px;
}

.menu ul {
    margin: 0 auto;
    width: 960px;
}

.menu ul li {
    list-style: none;
    float: left;
}

.menu ul li:hover {
    cursor: default;
}

.menu a {
    display: block;
    text-decoration: none;
    color: #FFFFFF;
    padding: 0 20px;
}

.menu:after,
.menu ul:after {
    content: '';
    display: block;
    clear: both;
}

.menu>ul>li>a {
    line-height: 39px;
}

.menu ul li:hover>a,
.menu ul li.active>a {
    background: #a32c2e;
    color: #FFFFFF;
}
.active ul {
    flex-direction: column;
    display: none;
    background:#333;
    padding: 0;
    position: abosolute;
    width: auto;
}
.active ul li{
    position: relative;
}
.active:hover ul {
    display: flex;
}

<div class="menu">
    <ul>
    <li class="active"><a href="/"><i class="glyphicon glyphicon-user"></i> Tester</a>
        <ul>
                <li><a href="#">sub-1</a></li>
                <li><a href="#">sub-2</a></li>
                <li><a href="#">sub-3</a></li>
        </ul>
    </li>

    <li><a href="/"><i class="glyphicon glyphicon-globe"></i> Comunidade</a></li>
    <li><a href="/"><i class="glyphicon glyphicon-shopping-cart"></i> Loja</a></li>

    <li style="float:right"><a href="/"><i class="glyphicon glyphicon-log-out"></i> Sair</a></li>
      </div>
    </ul>
   </nav>

Este é o erro.

2 answers

1


Using position: absolute in the second UL:

.menu li ul {
    position: absolute;
}

And removing the shores of the Uls with margin: 0:

.menu ul {
    margin: 0;
}

So you get the result you expect.

.menu {
    width: 100%;
    background: #1f1f1f;
    border-bottom: 4px solid #a32c2e;
    font-size: 11px;
}

.menu ul {
    margin: 0;
}

.menu ul li {
    list-style: none;
    float: left;
}

.menu ul li:hover {
    cursor: default;
}

.menu a {
    display: block;
    text-decoration: none;
    color: #FFFFFF;
    padding: 0 20px;
}

.menu:after,
.menu ul:after {
    content: '';
    display: block;
    clear: both;
}

.menu>ul>li>a {
    line-height: 39px;
}

.menu ul li:hover>a,
.menu ul li.active>a {
    background: #a32c2e;
    color: #FFFFFF;
}
.menu ul ul {
    display: none;
    background:#333;
    padding: 0;
    position: absolute;
    width: auto;
}
.menu ul li{
    position: relative;
}
.menu li:hover ul {
    display: inline;
    overflow: hidden;
}
.menu li:hover ul a {
    width: 100%;
}
<nav class="menu">
    <ul>
    <li class="active"><a href="/"><i class="glyphicon glyphicon-user"></i> Tester</a>
        <ul>
                <li><a href="#">sub-1</a></li>
                <li><a href="#">sub-2</a></li>
                <li><a href="#">sub-3</a></li>
        </ul>
    </li>

    <li><a href="/"><i class="glyphicon glyphicon-globe"></i> Comunidade</a>
        <ul>
                <li><a href="#">sub-1</a></li>
                <li><a href="#">sub-2</a></li>
                <li><a href="#">sub-3</a></li>
        </ul>
    </li>
    <li><a href="/"><i class="glyphicon glyphicon-shopping-cart"></i> Loja</a></li>

    <li style="float:right"><a href="/"><i class="glyphicon glyphicon-log-out"></i> Sair</a></li>
    </ul>
   </nav>

I hope it helped.

  • It worked perfectly, but in the second category of the menu Dropbox bugou, you know why?

  • Submenus went sideways instead of down.

  • I made a few minor changes to the CSS, updated the response.

  • It worked perfectly, but it created this problem http://prntscr.com/nn7q45

  • Try using a z-index: 999 no. menu, I believe this will solve.

1

Just add

position: absolute;

This is how:

.active:hover ul {
    display: flex;
}

It’s gonna be like this:

.active:hover ul {
    display: flex;
    position: absolute;
}

Upshot:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.