<main>
  
  <!--   First Dropdown -->
  <article>
    <dl class="dropdown">
      <dt class="dropdown__title"><span>First dropdown</span></dt>
      <dd class="dropdown__content">
        <ul>
          <li><a class="dropdown__header">First dropdown</a></li>
          <li><a>Tomato</a></li>
          <li><a>Potato</a></li>
          <li><a>Cucumber</a></li>
        </ul>
      </dd>
      <input type="hidden" name="first">
    </dl>
  </article>
  
  <!--   Second Dropdown -->
  <article>
    <dl class="dropdown">
      <dt class="dropdown__title"><span>Second dropdown</span></dt>
      <dd class="dropdown__content">
        <ul>
          <li><a class="dropdown__header">Second dropdown</a></li>
          <li><a>Hockey</a></li>
          <li><a>Soccer</a></li>
          <li><a>Football</a></li>
          <li><a>Basketball</a></li>
          <li><a>Foosball</a></li>
          <li><a>Gymnastics</a></li>
          <li><a>Curling</a></li>
          <li><a>Golf</a></li>
        </ul>
      </dd>
      <input type="hidden" name="first">
    </dl>
  </article>
  
  <!--   Third Dropdown -->  
  <article>
    <dl class="dropdown">
      <dt class="dropdown__title"><span>Long dropdown</span></dt>
      <dd class="dropdown__content">
        <ul>
          <li><a class="dropdown__header">Long dropdown</a></li>
          <li><a>Sass</a></li>
          <li><a>Less</a></li>
          <li><a>Option with a really long name to test overflow</a></li>
          <li><a>Stylus</a></li>
          <li><a>Compass</a></li>
        </ul>
      </dd>
      <input type="hidden" name="first">
    </dl>
  </article>
  
</main>
/* Colors */
$black: #464646;
$blackAlpha: rgba(#000, 0.12);
$gray: #868686;
$darkGray: #666666;
$red: #e75854;
$white: #fafafa;
$darkWhite: #eeeeee;
$backgroundColor: #1D3557;

/* Variables */

$anim: 250ms ease-in-out;

$triangleSize: 0.4rem;
$triangleRatio: 1.2;

$borderRadius: 0.2rem;

/* Placeholder */
%clearfix{
  &:before,
  &:after{
    content: " ";
    display: table;
  }
  &:after{ clear: both; }
}

/* Normalize */
* {
  box-sizing: border-box;
}
ul, dl{
  -webkit-margin-before: 0;
  -webkit-margin-after: 0;
  -webkit-padding-start: 0;
}
dd{
  -webkit-margin-start: 0;
}

/* Common style */

html{
  font-size: 62.5%;
  background: $white;
}
body{
  font-family: 'Lato', sans-serif;
  background-color: $backgroundColor;
  color: $black;
}

main{
  @extend %clearfix;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  height: 100vh;
  background-color: $backgroundColor;
  overflow: auto;
}

main{
  article{
    float: left;
    margin: 0 2.5%;
    margin-top: -5%;
    max-width: 20em;
    width: 30%;
  }
  
  article:first-of-type{
    margin-left: 0;
  }
  article:last-of-type{
    margin-right: 0;
  }
}

/* Dropy style */
.dropdown{
  position: relative;
	width: 100%;
  margin: 0 auto;
  
  margin-bottom: 1.5em; // Cosmetic value
}

.dropdown__title{
  position: relative;
  display: block;
  width: 100%;
  
  border-bottom: 1px solid $blackAlpha;
  text-decoration: none;
  font-size: 1.6rem;
  border-radius: $borderRadius;
  background: $white;
  color: $black;
  cursor: pointer;
  
  span {
    display: block;
    padding: 1rem 3rem 1rem 1.5rem;
    
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  transition: border-color $anim;

  &:hover{
    border-color: $gray;
  }
  &:after{
    content: "";
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    border-top: $triangleSize solid $gray;
    border-left: $triangleSize*$triangleRatio solid transparent;
    border-right: $triangleSize*$triangleRatio solid transparent;
  }
}

.dropdown__content{
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  
  ul{
    @extend %clearfix;
    z-index: 1;
    overflow: hidden;
    position: absolute;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: $borderRadius;
    max-height: 0;
    opacity: 0;
    margin-bottom: 40px;
    
    transition: opacity $anim, max-height $anim;
    
    list-style: none;
    background: $white;
    box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    
    li:first-child a:hover{
      border-radius: 0.2rem 0.2rem 0 0;
    }
    li:last-child a{
      margin-bottom: 1.5rem;
      &:hover{
        border-radius: 0 0 0.2rem 0.2rem;
      }
    }
  }
  li a{
    display: block;
    padding: 1rem 1.5rem;
    font-size: 1.4rem;
      
    color: $black;
    text-decoration: none;
    cursor: pointer;
    transition: background-color $anim, color $anim;
    
    &:hover{
      color: $darkGray;
      background-color: $darkWhite;
    }
  }
  .dropdown__header{
    border-bottom: 1px solid $blackAlpha;
    margin-bottom: 1.5rem;
    padding: 1rem 1.5rem;
    font-size: 1.6rem;
  }
  .selected{
    font-weight: 700 !important;
    color: $red;
  }
}
.dropdown.open{
  .dropdown__content ul{
    max-height: 30rem;
    overflow-y: scroll;
    opacity: 1;
  }
}
/**
 * Dropy
 */
var dropy = {
  $dropys: null,
  openClass: 'open',
  selectClass: 'selected',
  init: function(){
    var self = this;

    self.$dropys = $('.dropdown');
    self.eventHandler();
  },
  eventHandler: function(){
    var self = this;

    // Opening a dropy
    self.$dropys.find('.dropdown__title').click(function(){
      self.$dropys.removeClass(self.openClass);
      $(this).parents('.dropdown').addClass(self.openClass);
    });

    // Click on a dropy list
    self.$dropys.find('.dropdown__content ul li a').click(function(){
      var $that = $(this);
      var $dropy = $that.parents('.dropdown');
      var $input = $dropy.find('input');
      var $title = $(this).parents('.dropdown').find('.dropdown__title span');

      // Remove selected class
      $dropy.find('.dropdown__content a').each(function(){
        $(this).removeClass(self.selectClass);
      });

      // Update selected value
      $title.html($that.html());
      $input.val($that.attr('data-value')).trigger('change');

      // If back to default, remove selected class else addclass on right element
      if($that.hasClass('dropdown__header')){
        $title.removeClass(self.selectClass);
        $title.html($title.attr('data-title'));
      }
      else{
        $title.addClass(self.selectClass);
        $that.addClass(self.selectClass);
      }

      // Close dropdown
      $dropy.removeClass(self.openClass);
    });

    // Close all dropdown onclick on another element
    $(document).bind('click', function(e){
        if (! $(e.target).parents().hasClass('dropdown')){ self.$dropys.removeClass(self.openClass); }
    });
  }
};

$(function(){
  dropy.init();
});

External CSS

  1. https://fonts.googleapis.com/css?family=Playball|Lato:300,400

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js