Style SELECT (No Images + IE8 + Fixed Width)

Style Select Element in a cross-browser way.

by sstur

HTML

<form>
  <!-- IE8 requires that we specify a title attribute -->
  <div class="dselect" title>
    <select>
      <option>Item One</option>
      <option>Item Two</option>
    </select>
  </div>
  <p>This is an inline <span class="dselect" title>
    <select>
      <option>Item One</option>
      <option>Item Two</option>
    </select></span> select control.</p>
</form>

CSS

body {
  font-family: Arial, sans-serif;
  font-size: 12px;
}
.dselect {
  position: relative;
  display: inline-block;
  border: 1px solid #c7c7c7;
  border-radius: 3px;
  width: 200px;
  height: 25px;
  line-height: 22px;
  /* FF3.6+ */
  background: -moz-linear-gradient(top,  #fefefe 0%, #eeeeee 100%);
  /* Chrome10+, Safari5.1+ */
  background: -webkit-linear-gradient(top,  #fefefe 0%,#eeeeee 100%);
  /* IE10+ */
  background: -ms-linear-gradient(top,  #fefefe 0%,#eeeeee 100%);
  /* W3C */
  background: linear-gradient(to bottom,  #fefefe 0%,#eeeeee 100%);
  /* IE8 */
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fefefe', endColorstr='#eeeeee', GradientType=0);
}
.dselect select {
  margin: 0;
  padding: 0;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background: transparent none;
  border: 1px solid transparent;
  position: relative;
  z-index: 4;
  cursor: pointer;
  opacity: 0;
  filter: alpha(opacity=0);
}
.dselect:before {
  content: attr(title);
  display: block;
  position: absolute;
  left: 6px;
  top: 3px;
  right: 23px;
  bottom: 3px;
  padding-right: 6px;
  line-height: 20px;
  z-index: 2;
  white-space: nowrap;
  overflow: hidden;
  border-right: 1px solid #c7c7c7;
}
.dselect:after {
  content: " ";
  display: block;
  position: absolute;
  right: 8px;
  top: 10px;
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-top-color: #333;
  z-index: 3;
}
@-moz-document url-prefix() {
  /* for Firefox */
  .dselect select {
    display: block;
  }
}

JavaScript

jQuery(function($) {
  var update = function() {
    $(this)this.parent().attr('title', $$(this).val());
  };
  $(document).on('click change update', '.dselect>select', update);
  $('.dselect>select').trigger('update');
});