How to change the text color of first select option

后端 未结 6 900
我在风中等你
我在风中等你 2020-11-30 10:49

I have a select element which has several items. I want to change the color of its first item, but it seems the color only shows when you click on the select dropdown. What

6条回答
  •  一向
    一向 (楼主)
    2020-11-30 11:35

    If the first item is to be used as a placeholder (empty value) and your select is required then you can use the :invalid pseudo-class to target it.

    select {
      -webkit-appearance: menulist-button;
      color: black;
    }
    
    select:invalid {
      color: green;
    }

提交回复
热议问题