OPTION 文本的样式部分

2022-01-30 00:00:00 html css

我有一个包含几个 OPTION 元素的 SELECT 列表.这是我对部分选项文本进行样式设置的天真方法:

I have a SELECT list with several OPTION elements. Here is my naive approach to styling part of the option text:

<select name="color">
<option value="0">red <span style="font-weight: bold;">SLOW</span></option>
<option value="1">blue <span style="font-weight: bold;">SLOWER</span></option>
<option value="2">green <span style="font-weight: bold;">SLOWEST</span></option>
</select>

这不起作用:浏览器不喜欢 OPTION 元素内的 SPAN 元素.

This does not work: the browser does not like a SPAN element inside the OPTION element.

还有其他方法可以设置 OPTION 元素文本的一部分样式吗?

Is there some other way to style part of an OPTION element's text?

推荐答案

没有.option 以平台原生的方式设置样式,仅设置其中一部分的样式是行不通的.(这通常也不是一个特别好的主意.)

Nope. options are styled in a way native to the platform, and styling only a part of one doesn't work. (It usually wouldn't be a particularly good idea either.)

相关文章