How can I change the background color of option from select tag?

烂漫一生 提交于 2020-12-10 08:47:40

问题


I am trying to change the background colour for option from the select tag.

I tried select > option but it doesn't work.

My code below:

select {
  width: 100%;
  height: 32px;
  background-image: url("images/2017_04_form_select.jpg");
  padding-right: 25px;
  /* Safari 3-4, iOS 1-3.2, Android 1.6- */
  -webkit-border-radius: 0;
  /* Firefox 1-3.6 */
  -moz-border-radius: 0;
  /* Opera 10.5, IE 9, Safari 5, Chrome, Firefox 4, iOS 4, Android 2.1+ */
  border-radius: 0;
  background-repeat: no-repeat;
  background-position: right center;
  -webkit-appearance: none;
  -moz-appearance: none;
  -ms-appearance: none;
  -o-appearance: none;
  appearance: none;
  border: 1px solid #bdb9bb;
  margin-bottom: 20px;
}

select:-moz-focusring {
  color: transparent;
  text-shadow: 0 0 0 #000;
}

select::-ms-expand {
  display: none;
}

select>option {
  background: #e8e4e6;
}

回答1:


You just need to set a background-color for select option

select option {
  background-color: red;
}
<select>
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
</select>



回答2:


Have you tried just select.option ?

Or just option ?



来源:https://stackoverflow.com/questions/43740708/how-can-i-change-the-background-color-of-option-from-select-tag

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