Html 如何更改选定选项中的字体颜色?

Html 如何更改选定选项中的字体颜色?,html,css,forms,html-select,Html,Css,Forms,Html Select,我有以下HTML代码: <div class="register_account"> <form> <select> <option value="null">Select a Country</option> <option value="AX">Åland Islands</option> <option v

我有以下HTML代码:

<div class="register_account">
    <form>
        <select>
            <option value="null">Select a Country</option>
            <option value="AX">Åland Islands</option>
            <option value="AF">Afghanistan</option>
            <option value="AL">Albania</option>
            <option value="DZ">Algeria</option>
        </select>
    </form>
</div>
现在我想更改表单中“选择国家”和“选定”选项的文本颜色

请注意,示例如下:

编辑:

解决此问题的一个可能的解决方案可能是:

.register_account
{ 
    background: #0023C4;
    width:62%;
    padding:1.5%;
}

.register_account form select
{ 
    width:100%;
    font-size:0.8em;
    color:#fff;
    padding:8px;
    margin:5px 0;
    background: #0023C4;
    border: 1px solid #fff !important;
}
证明自己:

阅读


这应该可以正常工作,使用:hover,它会简单得多。

这条小线将解决问题,并提供您所需的信息,我想

A好的,您想在列表中以不同的颜色显示所选项目。在这里,我使用绿色作为所有项目,白色作为默认选择,试试这个

而且它不需要任何java脚本,您可以通过简单的CSS实现这一点

.register_account form option:not(:checked) { color: green; }
已编辑

//This line allows you to change the selected menu item color individually 
.register_account form option:checked { color: #0AD; }

可能重复的可能重复的代码我试过了,但颜色“黄色”不显示。打开选择。。。“选择一个国家”是黄色的(我使用Firefox24)谢谢。这就是我想做的。但如何更改所选选项的颜色?例如,如果我在菜单中选择阿尔巴尼亚,它将显示为白色。如何更改?在问题中,您提到“我想更改“选择一个国家”和表单中“选择的”选项的文本颜色。这就是我给出此答案的原因。如果选择白色,它将显示“选择一个国家”和所选项目相同的颜色?我更新了答案,看一看,我猜这就是您想要的答案。这正是我想要的。事实上,我在问题中这样写是因为我只找到了导致以下代码类型的答案:。register_account option[value=null],这并没有完全解决我的需求xD。再次感谢您的回复。
.register_account
  { background: #0023C4;
    width:62%;
    padding:1.5%;
   }

.register_account:hover form
    { width:100%;
      font-size:0.8em;
      color:#000;
      padding:8px;
      margin:5px 0;
      background: none;
      border: 1px solid #fff !important;
     }
.register_account form option:not(:checked) { color: green; }
//This line allows you to change the selected menu item color individually 
.register_account form option:checked { color: #0AD; }