简体   繁体   English

HTML:选择选项样式不起作用

[英]HTML: Select Option styling not working

I'm trying to style a select box, changing all of the color options to red. 我正在尝试设置选择框的样式,将所有颜色选项更改为红色。 However, when I load the webpage the select box still has color black. 但是,当我加载网页时,选择框仍然是黑色。 Any help please? 有什么帮助吗?

Here is the HTML & CSS: 这是HTML和CSS:

 select.selector option { color: red; } 
 <select style="font-size: 16px; padding: 4px;" name="category" id="categoryselector" class="selector"> <option disabled></option> <option value='all'>all</option> <option disabled></option> <option>Hardware and OS</option> </select> 

And here is a JSFiddle 这是一个JSFiddle

You're applying the color to the options within the select box. 您正在将颜色应用于选择框中的选项。 To apply it to the visible select box, use: 要将其应用于可见选择框,请使用:

select.selector{
color:red;
}

Select option styling doesn't work in Chrome (MAC OS X) , but it will work in Firefox on all systems as well as Chrome (Windows 7). 选择样式样式在Chrome(MAC OS X)中不起作用,但它可以在所有系统和Chrome(Windows 7)的Firefox中使用。

You can check the detailed description here: Dealing with the select nightmare 您可以在此处查看详细说明: 处理选择的噩梦

Please, try this code: 请尝试以下代码:

select option {
    background: rgba(0,0,0,0.3);
    color:red;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM