html - 如何自定义两个不同颜色的select标签?

标签 html css select

我的网页中有两个选择标签。但是我来定制它们两种不同的颜色。关于我该怎么做的任何建议?

下面是我的代码。

select {
  list-style-type: none;
  padding: 0;
  margin: 0;
  width: 80%;
  overflow-y: auto;
  text-align: center;
  border: 1px;
  background-color: #4472C4;
}

select option {
  border: none;
  margin-top: -1px;
  /* Prevent double borders */
  padding: 12px;
  text-decoration: none;
  font-size: 1.5vw;
  color: black;
  display: block
}

select option :hover:not(.header) {
  background-color: aliceblue;
  color: white;
}
<td width=20% style="background-color: #4472C4">
  <label>
    <h2>Our Recommended Favorites</h2>
    <select size=9 id="myList" class="list-content" onchange="setPicture();">
    </select>
  </label>
</td>
<td width=40%>
  <label>
    <select size=3 id="myList-1" class="list-content"></select>
  </label>
</td>

最佳答案

您可以使用 id 的 # 的 css 选择器来设置它们的样式 你可以阅读更多关于它的信息。在 this site

在这种情况下,您可以使用以下代码为它们提供不同的颜色:

#myList {
    background-color: green;
}

#myList-1 {
    background-color: red;
}

关于html - 如何自定义两个不同颜色的select标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59071587/

相关文章:

php - Laravel 没有将样式表添加到头部,而是添加到主体

html - CSS - 简单的特异性问题 - '#div-id ul' - 不会覆盖 'ul' 的列表样式

html - IE8 中输入的 z 索引是怎么回事?

html - 尝试使用 min-width 给第一个元素一个宽度

mysql - select-table sql自动更新(触发)

php - 如何 $_POST 从 PHP 类别列表函数中选择值?

html - 具有 100% 高度子 div 的 BS 3.0 粘性页脚

javascript - 基于一天中的小时的 body 背景 JS

html - 元素从父元素继承样式,即使以其他方式显式定义也是如此

mysql 从选择中选择