Can you have multiple font colors in select field?

自古美人都是妖i 提交于 2019-12-07 05:06:26

问题


Is it possible to have an HTML select field where the OPTION text is of different colors?

<select>
<option>Black_text (yellow_text)</option>
</select>

I tried using an CSS SPAN element to color the text but that doesn't seem to work.

Any ideas?

UPDATE: Note, I'm trying to have multiple font colors on the same OPTION row. I've seen quite a few tutorials on how to style the entire OPTION row but I'm trying to style elements within the same option row.


回答1:


Try to style the option elements itself:

<option style="…">Label</option>

But I doubt that browsers support much styling of these elements.


Edit

I'm trying to have multiple font colors on the same OPTION row.

That’s not possible as the option element does only allow text as content:

<!ELEMENT OPTION - O (#PCDATA)         -- selectable choice -->



回答2:


You probably can't do it with a plain vanilla select list. However, it probably would be possible to use Javascript + HTML + CSS to make your own "select list" using just div and span elements and that correct onclick, and onmouseover javascript. Would be much more difficult, but if it's really important, you could probably get it to work.




回答3:


Why dont you put a background image on every row like this:

<option style="background-image: multicolorimage.jpg>some text</option>

sorry, wrong answer. At first I didnt understand what you are trying to do so disregard my post :)




回答4:


No, but you can use stuff like http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ that builds its own selectbox using button and span tags.



来源:https://stackoverflow.com/questions/651146/can-you-have-multiple-font-colors-in-select-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!