Here is what I am trying to acheive:
- Standard SELECT form element
- The FIRST option will have font-family of Verdana
- All other options will have font-family of Arial
- After selecting an option, the SELECT will appear in the font-family of that option
- This is done using a combination of CSS and JS. JS is used to change the class of the SELECT so that it can apply the correct style.
I have got this working to the above requirements in Firefox and IE11 but not in Chrome 36 (Windows).
Here is a JSFiddle: http://jsfiddle.net/KhvJc/
CSS:
select {
width: 150px;
font-size: 12px;
padding: 5px;
height: 30px;
}
/* when the first option is selected */
select.empty {
color: #959595;
font-family: Verdana;
}
/* all options except the first when the first option is selected and the select has focus */
select.empty:focus option:not(:first-child) {
color: #282525;
font-family: Arial;
}
/* first option when the select has focus */
select:focus option:first-child {
color: #BDBDBD;
font-family: Verdana;
}
JS:
$('select').change(function(){
if($(this).val() == '')
{
$(this).addClass('empty');
}
else
{
$(this).removeClass('empty');
}
}).change();
HTML:
<select>
<option value="">Empty Option</option>
<option value="1">Option 1</option>
<option value="1">Option 2</option>
<option value="1">Option 3</option>
<option value="1">Option 4</option>
</select>
As you will see, in Chrome it does not apply the font-family
to individual options but it does manage to apply the color
. Anybody know how to fix this?