HTML选择具有多种颜色的DropDown列表

时间:2010-04-27 10:57:43

标签: html colors html-select

是否可以在下拉列表中为不同的项目设置不同的颜色?

例如:

选项1 =绿色
选项2 =蓝色

4 个答案:

答案 0 :(得分:11)

这是你想要的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>

答案 1 :(得分:3)

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>

答案 2 :(得分:1)

我猜你的意思是select?这应该有效:

option:nth-child(1) { background: green; }
option:nth-child(2) { background: blue; }

答案 3 :(得分:0)

Exception in thread "AWT-EventQueue-0" 
java.lang.ArrayIndexOutOfBoundsException: 1
    at controller.TaskController.openFile(TaskController.java:213)
    at controller.TaskController.lambda$11(TaskController.java:110)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)