【问题标题】:Background transparent is not working in Safari背景透明在 Safari 中不起作用
【发布时间】:2021-10-13 10:38:00
【问题描述】:

我有一个透明背景的下拉菜单。它在 Chrome 中运行良好,但在 Safari 中,select 具有这种灰色渐变背景。

这是我的 CSS:

div.controls {
  div.wrapper {
    select {
      background: transparent;
      border: none;
      color: blue;
      width: 100px;
      text-overflow: ellipsis;

      option {
        width: 200px;
      }
    }
  }
}

我该如何解决这个问题?

【问题讨论】:

    标签: html css safari


    【解决方案1】:

    您可以使用以下方法禁用select-元素的默认外观:

    -webkit-appearance: none;
    

    更多信息请参见MDN: appearance (-moz-appearance, -webkit-appearance)

    示例:

    select {
      -webkit-appearance: none;
      background: transparent;
      border: none;
      color: blue;
      width: 100px;
    }
    <select>
      <option>Option 1</option>
    </select>

    【讨论】:

    • 但这会删除下拉箭头。
    • @saralance 确实如此。我猜这是禁用默认样式的权衡。
    猜你喜欢
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 2011-07-28
    • 2016-10-23
    • 1970-01-01
    相关资源
    最近更新 更多