skip to Main Content

To put it very simple, I want to change the background color of the main field (not sure what else to call it, it’s the field marked in red in the example) of a HTML element. I do not want to change the background color of the dropdown fields.

Is this possible? If so, how?

enter image description here

Source code:

<select>
   <option>Item 1</option>
   <option>Item 2</option>
   <option>Item 3</option>
</select>

2

Answers


  1. You can use css selectors: select and select option (I put red for options, but you can change color to whatever you like)

    select {
      background-color: yellow;
    }
    select option {
      background-color: red;
    }
    <select>
       <option>Item 1</option>
       <option>Item 2</option>
       <option>Item 3</option>
    </select>
    Login or Signup to reply.
  2. One way would be to style de select and the option

    option{
      background-color: white;
    }
    
    select { 
      background-color: yellow;
    }
    <select>
       <option value="3">tewe</option>
       <option value="8">eerer</option>
       <option value="5">ererere</option>
    </select>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search