I'm using placeholders for text inputs which is working out just fine. But I'd like to use a placeholder for my selectboxes as well. Ofcourse I can just use this code:
<select>
<option value="">Select your option</option>
<option value="hurr">Durr</option>
</select>
But the 'Select your option' is in black instead of lightgrey. So my solution could possibly be CSS-based. jQuery is fine too.
This only makes the option grey in the dropdown (so after clicking the arrow):
option:first {
color: #999;
}
Edit: The question is: how do people create placeholders in selectboxes? But it has already been answered, cheers.
And using this results in the selected value always being grey (even after selecting a real option):
select {
color:#999;
}
I see signs of correct answers but to bring it all together this would be my solution.
I couldn't get any of these to work currently, because for me it is (1) not required and (2) need the option to return to default selectable. So here's a heavy handed option if you are using jquery:
Try this for a change
Something like this maybe?
HTML:
CSS:
JavaScript:
Working example: http://jsfiddle.net/Zmf6t/
That solution works in FireFox also:
Without any JS.
Here I have modified David answer (accepted answer). On his answer, he put disabled and selected attribute on option tag but when we also put hidden tag then it will look much better. By adding an extra hidden attribute on option tag, will prevent the "Select your option" option from being re-selecting after the "Durr" option is selected.