html - 有没有办法在 css 中选择一个打开的选择框?

标签 html css select selector html-select

在将 webkit-appearance 属性设置为 none 后,我将背景图像(向下箭头)设置为选择框。打开选项列表时,我想显示另一个背景图像(向上箭头)。是否有伪类或其他东西?我在研究期间找不到任何东西......

最佳答案

您可以使用 :focus 伪类。

但这将指示“打开”状态,当 <select> 时也是如此通过选项卡选择或刚刚选择了一个元素。为了避免这种情况,您可以使用类似 select:hover:focus 的东西但这相当丑陋,不是可靠的解决方案。

select:focus {
  background-color: blue;
  color: white;
}
<select>
  <option>Click me</option>
  <option>A</option>
  <option>B</option>
  <option>C</option>
</select>

关于html - 有没有办法在 css 中选择一个打开的选择框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693560/

相关文章:

javascript - 如何更改所选选项的背景颜色? (HTML)

html - 如何更改选择标签上的向下箭头

php - 我的 php mysql 无法从数据库检索数据

javascript - 如何仅切换标题元素而不是列表

javascript - Angular : how to load data on a partial?

css - IE6-7表格里面li留一个缺口

jquery - 文本对齐居中而不是按钮中的文本居中

javascript - 相对于另一个对象对齐一个对象 Angularjs

php - MySQL - 如何选择表中的行,其中 id 值位于另一个表中的逗号分隔字段中?

mysql - “SELECT…IN…” 运算符(operator)未在程序中工作