Is there any secret behind editing a option tag with css? I just can't solve this issue
<option> FirstName <span class = "foo">SecondName</span> </option>
.foo{
开发者_高级运维color:#666666;
}
What am I missing?
<option>
elements cannot contain anything other than text. So no, you can't apply a style to a section of their content.
Just don't use a <select>
, or don't bother about styling. From your use case, it doesn't really look suitable anyway. It'd be better just to type the name, wouldn't it?
I know this question is old, but there are some new developments in the world of CSS!
color
property on select
will now set color of option(s) text (including selected), while adding / over-riding color to select option
.
CSS:
select {
color: white; /* color of selected option */
}
select option {
color: black; /* color of other options */
}
精彩评论