Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: Select Option styling not working

Tags:

html

css

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:

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

like image 410
Henry Zhu Avatar asked Jul 08 '16 21:07

Henry Zhu


People also ask

Can you style HTML select?

The select is set to display: block by default but you can style it display: inline-block; width: auto; if you'd like it to sit alongside a label .

How do I style a selection dropdown in CSS?

There are many ways to design a <select> dropdown menu using CSS. The Dropdown Menu is mainly used to select an element from the list of elements. Each menu option can be defined by an <option> element that can nested inside the <select> element.

How do I change the select CSS option?

To change the selected option background-color CSS style, we can set the style attribute of the select and option elements. to set the whole select element to background color 009966 and color FFF . Then we override the the styles in the option elements with style="background: white; color: black;" .


2 Answers

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).

You can check the detailed description here: Dealing with the select nightmare

like image 109
Vikas Jindal Avatar answered Oct 03 '22 23:10

Vikas Jindal


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;
}
like image 42
Neil K Avatar answered Oct 04 '22 00:10

Neil K