Last active
December 28, 2015 05:09
-
-
Save aronbudinszky/7448246 to your computer and use it in GitHub Desktop.
Nice, compact, mobile-friendly select styling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="select"> | |
<select name=""> | |
<option value=""> </option> | |
<option value="1">Option 1</option> | |
<option value="2">Option 2</option> | |
</select> | |
</div> | |
<script> | |
// select element styling | |
jQuery(document).ready(function($) { | |
jQuery("select").each(function(){ | |
var title; | |
if( jQuery("option:selected", this).val() != "") { | |
title = jQuery("option:selected", this).text(); | |
} else { | |
title = " "; | |
} | |
jQuery(this).after('<span>' + title + '</span>').change(function() { | |
var val = jQuery("option:selected", this).text(); | |
jQuery(this).next().text(val); | |
}); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.select > select { | |
position: absolute; | |
top: 0; | |
left: 0; | |
z-index: 1; | |
width: 100%; | |
opacity: 0; | |
filter: alpha(opacity=0); | |
} | |
.select > span { | |
position: absolute; | |
top: 0; | |
left: 0; | |
z-index: 0; | |
width: 100%; | |
font-size: 14px; | |
line-height: 20px; | |
padding: 4px 0; | |
display: block; | |
color: #555; | |
border: #ccc solid 1px; | |
background-color: #bde1ec; | |
border-radius: 4px; | |
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); | |
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); | |
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment