Alignment drop down menu

Asked

Viewed 1,671 times

4

I have a horizontal navigation bar, which has submenus. Currently the submenu is aligned to the left of the menu to which it belongs. As in this image:

Menu atual

I would like the submenu to be aligned to the right of the menu to which it belongs. As in this image:

inserir a descrição da imagem aqui

The code I’m using to create this menu is here (html and css are in a single file):

<html>
<head>
    <style>
        *{
            margin: 0;
            padding: 0;
         }
        body{
            font-family: arial, helvetica, sans-serif;
            font-size: 12px;
        }

        .menu{
            list-style:none;
            border:1px solid #c0c0c0;
            float:right;
        }
        .menu li{
            position:relative;
            float:right;
            border-right:1px solid #c0c0c0;
        }

        .menu li a{
            color:#333; 
            text-decoration:none; 
            padding:5px 10px; 
            display:block;
        }

        .menu li a:hover{
            background:#333;
            color:#fff;
            -moz-box-shadow:0 3px 10px 0 #CCC;
            -webkit-box-shadow:0 3px 10px 0 #ccc;
            text-shadow:0px 0px 5px #fff;
        }
        .menu li  ul{
            position:absolute;
            top:25px;
            left:0;
            background-color:#fff;
            display:none;
        } 

        .menu li:hover ul, .menu li.over ul{
            display:block;
        }

        .menu li ul li{
            border:1px solid #c0c0c0;
            display:block;
            width:150px;
        }
    </style>
</head>

<body>
    <ul class="menu">
        <li> <a>Nome aleatorio</a> </li>
        <li>
            <a>Bruno Pinheiro</a>
            <ul>
                <li><a href="#">Editar Perfil</a></li>
                <li><a href="#">Logout</a></li>
            </ul>
        </li>
    </ul>
</body>

1 answer

3


Just change of left: 0; for right: 0; in the line I refer to in this piece of CSS:

.menu li ul {
    position: absolute;
    top: 25px;
    left: 0;   /*   Mude aqui... para right: 0;   */
    background-color: #fff;
    display: none;
}

And the result will be: http://jsfiddle.net/uuu5ttek/

  • 1

    Thank you very much Sergio. That’s just what I needed.

Browser other questions tagged

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