【问题标题】:How do I change the background color of the main cell of a html dropdown?如何更改 html 下拉菜单主单元格的背景颜色?
【发布时间】:2023-02-13 23:13:28
【问题描述】:

说的很简单,我想改变的背景颜色主场(不知道还能叫它什么,它是示例中用红色标记的字段)HTML 元素。我不想更改下拉字段的背景颜色。

这可能吗?如果是这样,如何?

源代码:

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

【问题讨论】:

标签: html css dropdown html-select


【解决方案1】:

您可以使用 css 选择器:选择和选择选项(我将选项设置为红色,但您可以将颜色更改为您喜欢的任何颜色)

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

【讨论】:

    【解决方案2】:

    一种方法是样式化 select 和 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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 2023-01-05
      • 2020-09-03
      • 2014-02-02
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      相关资源
      最近更新 更多