Skip to content

Instantly share code, notes, and snippets.

@tessalt
Created September 26, 2012 03:12
Show Gist options
  • Save tessalt/3785780 to your computer and use it in GitHub Desktop.
Save tessalt/3785780 to your computer and use it in GitHub Desktop.
#selects
<select>
<option>My Assets</option>
<option>All Assets</option>
<option>Other Things</option>
<option>Another really long option</option>
</select>
$("select").wrap('<div class="box"/>');
$("select").after("<span class='selecttext'></span>");
var val = $("select option:selected").text();
$(".selecttext").text(val);
$("select").change(function(){
var val = $("select option:selected").text();
$(".selecttext").text(val);
});
body {
font-family: Arial, sans-serif;
font-size: 14px;
margin: 20px;
}
.box {
position: relative;
background: #e6e6e6;
background-image: -moz-linear-gradient(top, white, #e6e6e6);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, white), color-stop(1, #e6e6e6));
background-image: linear-gradient(top, white, #e6e6e6);
border: 1px solid #aeaeae;
display: inline-block;
*display: inline;
zoom: 0;
border-radius: 5px;
box-shadow: 0 1px 1px #d2d2d2;
}
select {
z-index: 10;
position: relative;
opacity: 0;
border: none;
-webkit-appearance: none;
background: none;
outline: none;
padding: 4px 12px;
}
.selecttext {
display: inline-block;
*display: inline;
zoom: 1;
background: transparent;
position: absolute;
left: 5px;
z-index: 9;
color: #666;
padding-top: 4px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment