【发布时间】:2018-09-22 21:43:34
【问题描述】:
我正在使用 select2 下拉菜单,并希望为每个选项设置不同的颜色。
示例:
<select class="select2" name="fruit">
<option class="red-option">Apple</option>
<option class="green-option">Kiwi</option>
<option class="blue-option">Grape</option>
</select>
我可以对渲染后的选定选项进行着色,如下所示:
.select2-selection__rendered[title="Apple"] {
color: red !important;
}
如何对 select2 下拉菜单中的选项进行着色 - 基于选项类('red-option')或值('Apple')?
PS:我使用 bootstrap 3.3 + jQuery,如果必须的话,不介意使用 JS 来执行此操作。
【问题讨论】:
标签: html css twitter-bootstrap-3 jquery-select2