我正在使用以下 HTML 代码在我的表单中包含一个 select2 控件,如下所示。
<select id="element_id" class="select2" style="width:100%">
<option value="e1" >Element 1</option>
<option value="e2" >Element 2</option>
<option value="e3" >Element 3</option>
</select>
我正在使用以下样式来格式化列表项和选定项的字体。
<style>
#s2id_element_id .select2-container--default .select2-selection--single .select2-selection__rendered
{
color: green ;
}
</style>
这不会将列表项和选定项着色为绿色。注意:我只需要这个特定的选择框来拥有样式,而不是其他的。所以我将 css id 选择器用于特定的 select2 控件。
谢谢。
原文由 Wajira Weerasinghe 发布,翻译遵循 CC BY-SA 4.0 许可协议
以下是您需要用于设置 select2 输入样式的类列表:
如果你愿意,你可以在我创建的这个 JSBin 中尝试一下,这样你就可以测试一下。