简体   繁体   English

如何在 html select 中设置选项文本的跨度标记

[英]How to style span tag of option text in html select

Stackblitz 堆栈闪电战

I have a scenario where the first option of my HTML select includes an asterisk which is supposed to be in a red color.我有一个场景,我的 HTML select 的第一个选项包括一个应该是红色的星号。 However I am unable to style the asterisk and it always appears in the default black color.但是我无法设置星号的样式,它总是以默认的黑色显示。

I have included the stackblitz example and even if i use an image of asterisk it still does not work as intended.我已经包含了 stackblitz 示例,即使我使用星号图像,它仍然无法按预期工作。

You can't just style the span tag, because only plain text can be placed in the option element.您不能只设置 span 标签的样式,因为只能在 option 元素中放置纯文本。 So actually there is no span tag.所以实际上没有跨度标签。 在此处输入图像描述 But you can add style to select, and color will be red in select element.但是您可以为 select 添加样式,并且 select 元素中的颜色将为红色。

 select { color: red; }

Stackblitz堆栈闪电战

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM