I'm trying to change font color of the first select option which has Bootstrap's form-control
class as follows:
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
I tried styling it using the first-child
attribute as follows, but it colors everything in red:
select.form-control { color: red; }
select.form-control option { color: black; }
select.form-control option:first-child { color: red; }
I even tried styling it inline, but it is still unable to override Bootstrap's css:
<select class="form-control">
<option style="color: red;" color="red">1</option>
<option>2</option>
<option>3</option>
</select>
Interestingly, the css correctly styles the first element when it's a multiple
style, but that's not what I need:
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
Here's a codepen reproducing this: http://codepen.io/anon/pen/MKjYjq
UPDATE 1:
By first element I mean the first option within select (i.e. <option>1</option>
). I'd like it to be red, and the rest black.
Unlike some comments reported with the original Codepen, even the inline approach doesn't work for me in Chrome 47, Safari 9 and Firefox 42 on Mac:
The desired option is where number 2
in the image above (along with other options below it) is black, but option 1
is red.