我使用以下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>
Run Code Online (Sandbox Code Playgroud)
我使用以下样式来格式化列表项和所选项的字体.
<style>
#s2id_element_id .select2-container--default .select2-selection--single .select2-selection__rendered
{
color: green ;
}
</style>
Run Code Online (Sandbox Code Playgroud)
这不会将列表项和所选项目以绿色着色.注意:我只需要这个特定的选择框来拥有样式而不是其他.所以我使用css id选择器进行特定的select2控制.
谢谢.