【发布时间】:2010-04-27 10:57:43
【问题描述】:
下拉列表中的不同项目可以有不同的颜色吗?
例如:
选项 1 = 绿色
选项 2 = 蓝色
等等
【问题讨论】:
-
可以,在css的选项标签中使用class或id
标签: html colors html-select
下拉列表中的不同项目可以有不同的颜色吗?
例如:
选项 1 = 绿色
选项 2 = 蓝色
等等
【问题讨论】:
标签: html colors html-select
这就是你想要的Styling Dropdown Lists
<style type="text/css">
option.red {background-color: #cc0000; font-weight: bold; font-size: 12px;}
option.pink {background-color: #ffcccc;}
</style>
<select name=colors>
<option class="red" value= "../getting_started/">Getting Started </option>
<option class="pink" value= "../getting_started/html_intro1.htm">- Intro to HTML
</option>
</select>
【讨论】:
<Style tyle=,但没有找到任何结果。我刚刚对此进行了测试,即使您删除了tyle,颜色也可以正常工作,而将第一行改为<style =text/css>
CSS 和 HTML
#option-1 {
color: red;
}
#option-2 {
color: green;
}
#option-3 {
color: yellow;
}
#option-4 {
color: blue;
}
<select>
<option id="option-1">Option 1</option>
<option id="option-2">Option 2</option>
<option id="option-3">Option 3</option>
<option id="option-4">Option 4</option>
</select>
【讨论】:
我猜你的意思是select?这应该有效:
option:nth-child(1) { background: green; }
option:nth-child(2) { background: blue; }
等
【讨论】:
:nth-child 在 IE 中不起作用(并且在其他一些浏览器中存在问题)。
<div class="col-lg-3">
<label>Job Status:</label>
<select type="text" name="fname" class="form-control" placeholder="Job Status" >
<option value="">Select Status</option>
<option class="btn btn-success" value="Working">Working</option>
<option class="btn btn-warning" value="In Proccess">In Proccess</option>
<option class="btn btn-danger" value="Closed">Closed</option>
</select>
</div>
【讨论】: