Change Color of Selected Option in <select multiple> [duplicate]

谁说胖子不能爱 提交于 2021-02-10 13:16:12

问题


I'm having this problem where I need to change the color of a/multiple option element(s) when clicked/ selected. Default color is blue when clicked, I believe we should have a solution for this now since I've try to search for solutions but to no avail. Hoping to do this in CSS or vanilla JS. no libraries or frameworks.

Link to sample code


回答1:


select[multiple]:focus option:checked {
  background: red linear-gradient(0deg, red 0%, red 100%);
}
<select multiple>
  <option value="1">one</option>
  <option value="2" selected>two</option>
  <option value="3">three</option>
</select>


来源:https://stackoverflow.com/questions/50618602/change-color-of-selected-option-in-select-multiple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!