0

Here's my code:

<select id="xyz" name="xyz">
  <option></option>
  <option value="Monday">Monday</option>
  <option style="color:red;" selected="selected" value="Tuesday">Tuesday</option>
  <option value="Wednesday">Wednesday</option>
</select>

When I open the drop down, the option is red. However, the selected item shown when the drop down is closed is NOT red.

How do I also make the item red when the drop down is closed?

AJPerez
  • 3,435
  • 10
  • 61
  • 91
Richard Tinkler
  • 1,635
  • 3
  • 21
  • 41

3 Answers3

2

You can do this by using CSS

option[selected] {
            color: red;
        }
        option {
            color: black;
        }
        select {
            color: red;
        }
<select id="xyz" name="xyz">
    <option></option>
    <option value="Monday">Monday</option>
    <option  selected="selected" value="Tuesday">Tuesday</option>
    <option value="Wednesday">Wednesday</option>
 </select>
Ankur Bhadania
  • 4,123
  • 1
  • 23
  • 38
1

This is somehow the same as this post

You can try this in your css and change styles until u achieve what u needed

select{
  width: 150px;
  height: 30px;
  padding: 5px;
  color: red;
}
select option { color: black; }
select option[selected='selected']{
  color: red;
}
<select id="xyz" name="xyz">
    <option></option>
    <option value="Monday">Monday</option>
    <option style="color:red;" selected="selected" value="Tuesday">Tuesday</option>
    <option value="Wednesday">Wednesday</option>
</select>
Community
  • 1
  • 1
Abbr
  • 372
  • 1
  • 15
0

This will work

Your HTML Code

<select id="xyz" name="xyz" onchange="this.className=this.options[this.selectedIndex].className" class="black">
    <option></option>
    <option value="Monday"  selected="selected">Monday</option>
    <option class="red"  value="Tuesday">Tuesday</option>
    <option value="Wednesday">Wednesday</option>
</select>

Your CSS Code will be

option{ color:black}
.black{ color:black}
.red{ color:red; }