JSFiddle - React, Tailwind, and code Playground

by oshirowanen

HTML

<div class="menu">
    <div class="navigation">Account 1 ▼</div>
    <div class="dropdown">
        picture of user 1 goes here <br>
        other options 1 go here <br>
        further options 1 go here
    </div>
    <div class="navigation">Account 2 ▼</div>
    <div class="dropdown">
        picture of user 2 goes here <br>
        other options 2 go here <br>
        further options 2 go here
    </div>
</div>

CSS

.menu {
    position: relative;
    background-color:silver;
    font-family:Arial;
    font-size:12px;
    height:25px;
}

.navigation {
    float:left;
    padding:5px 10px 5px 10px;
    cursor:pointer;
}

.navigation::selection { background:transparent; }
.navigation::-moz-selection { background:transparent; }

.navigation:hover {
    background-color:gray;
}

.navigation.active {
    border:1px solid black;
    border-bottom-color:white;
    padding:4px 9px;
    background-color: white;
    position:relative;
    z-index:1;
}

.dropdown {
    display:none;
    border:1px solid black;
    border-bottom-width:2px;
    background-color:white;
    position:absolute;
    top:24px;
    padding:5px 10px;
    cursor:pointer;
}

JavaScript

/* facebook style dropdown menu left */

$('.dropdown').each(function() {
    $(this).css('left', $(this).prev().position().left);
});

$('.navigation').click(function() {
    $(this).siblings('.navigation.active').click();
    $(this).toggleClass('active').next().toggle();
});