%link{ rel: "stylesheet", href:"https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" }

.dropdown.demo-left
  %a.dropdown__toggle{href:'#', aria: { haspopup: true } }
    Left-aligned Dropdown
    %i.fa.fa-caret-down{ aria: { hidden: true } }
  %ul.dropdown__menu{ style: 'left: 0;' }
    %li.dropdown__menu-item
      %a{ href: '#'}
        1
    %li.dropdown__menu-item
      %a{ href: '#'}
        2
    %li.dropdown__menu-item
      %a{ href: '#'}
        3 
.dropdown.demo-right
  %a.dropdown__toggle{href:'#', aria: { haspopup: true } }
    Right-aligned Dropdown 
    %i.fa.fa-caret-down{ aria: { hidden: true } }
  %ul.dropdown__menu{ style: 'right: 0;' }
    %li.dropdown__menu-item
      %a{ href: '#'}
        One
    %li.dropdown__menu-item
      %a{ href: '#'}
        Two
    %li.dropdown__menu-item
      %a{ href: '#'}
        Three

.vertical-spacing

.dropdown.demo-left
  %a.dropdown__toggle{ href:'#', aria: { label: 'Settings', haspopup: true } }
    %i.fa.fa-caret-down{ aria: { hidden: true } }
  %ul.dropdown__menu{ style: 'left: 0;' }
    %li.dropdown__menu-item
      %a{ href: '#'}
        Uno
    %li.dropdown__menu-item
      %a{ href: '#'}
        Dos
    %li.dropdown__menu-item
      %a{ href: '#'}
        Tres

.dropdown.demo-right
  %a.dropdown__toggle{ href:'#', aria: { label: 'Options', haspopup: true } }
    %i.fa.fa-ellipsis-v{ aria: { hidden: true } }
  %ul.dropdown__menu{ style: 'right: 0;' }
    %li.dropdown__menu-item
      %a{ href: '#'}
        一
    %li.dropdown__menu-item
      %a{ href: '#'}
        二
    %li.dropdown__menu-item
      %a{ href: '#'}
        三
View Compiled
/* For this Codepen purpose */
body {
  font-family: monospace;
  background-color: #52d2bc;
}

.vertical-spacing {
  height: 300px;
  display: block;
}

.demo-left {
  float: left;
}

.demo-right {
  float: right;
}

/* ****************************************** */
/* Dropdown menu styling */
/* ****************************************** */

.dropdown {
  display: block;
  transition-duration: 0.2s;
  position: relative;
}

.dropdown > a {
  display: block;
  padding: .6em 1em;
}

/* all links */
a {
  display: block;
  height: 100%;
  text-decoration: none;
  color: black;
  padding: .6em 1em;
}

/* menu item */
li.dropdown__menu-item {
 display: block;
 transition-duration: 0.2s;
 position: relative;
}

/* When menu item is hovered, tabbed, or contains child with focus, */
li.dropdown__menu-item:focus,
li.dropdown__menu-item:focus-within,
li.dropdown__menu-item:hover {
  background-color: #b2f1e6;
  cursor: pointer;
}

/* Ensures that hover background won't cover bottom outline of focused item above*/
li.dropdown__menu-item:focus,
li.dropdown__menu-item:focus-within {
  z-index: 1;
}
 
/* Toggle styling when dropdown is focused, hovered, or contains child with focus */
.dropdown:focus,
.dropdown:focus-within,
.dropdown:hover > a.dropdown__toggle {
  text-decoration: underline;
  cursor: pointer;
}

ul.dropdown__menu {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  transition: all 0.2s ease;
  display: none;
  background-color: white;
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 7rem;
/*  When toggle is focused, bottom border cuts off when dropdown is open.   */
  margin-top: 1rem;
}

/* Dropdown menu when dropdown is focused or child element is focused*/
.dropdown:focus > ul.dropdown__menu,
.dropdown:focus-within > ul.dropdown__menu {
  visibility: visible;
  opacity: 1;
  display: block;
}

.dropdown__menu-item {
  clear: both;
  width: 100%;
  text-align: left;
}
// Still would need javascript to add keyboard arrow support, aria-expanded 

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.