css - IE中select的背景 left if right

标签 css internet-explorer background-position

您好,我设计了一个跨浏览器选择,它在浏览器 chrome、IE 和 safari 上具有相同的设计。我为此使用了以下代码(在右侧的空白处有正常的箭头图标):

select{
  transition: border-color ease-in-out 0.15s;
  background: transparent;
  border: 1px solid $BORDER_COLOR;
  outline: 0;
  padding: 5px 25px 5px 5px;

  -webkit-user-select: none;
  -moz-user-select: -moz-none;
  -ms-user-select: none;
  user-select: none;

  -webkit-appearance: none;
  -moz-appearance: radio-container;
  appearance: none;
  background: url("arrow_down_grey.svg") no-repeat center right;
}

select::ms-expand {
  display: none;
}
<body>
  <label>City</label>
  <select>
    <option>Zurich</option>
    <option>Vienna</option>
    <option>Berlin</option>
  </select>
  
  <label>Country</label>
  <select>
    <option>Switzerland</option>
    <option>Austria</option>
    <option>Germany</option>
  </select>
</body>

在浏览器 chrome 和 safari(台式机和平板电脑)上它工作正常,看起来像这样:

enter image description here

但在 IE 上,图标在左侧,而不是像在其他浏览器中那样在右侧:

enter image description here

我发现了一条评论,说 IE 无法在 select 中正确设置背景位置。有没有好的解决方法?我什么也没找到。

谢谢。

最佳答案

首先,你的 CSS 中有一个拼写错误:

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

应该是:

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

你忘记了-

其次,如果我看这个JSFIDDLE在 IE11 中,我看到箭头像你想要的那样向右对齐。你也看到了吗?

关于css - IE中select的背景 left if right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37340230/

相关文章:

javascript - Bug - IE 11 "Object doesn' t 支持元素节点上的属性或方法“appendChild”

html - 当按钮没有关联的 "name"时,使用 Excel VBA 单击 Internet Explorer 中的按钮

javascript - 遍历 Sprite 并保存背景位置

CSS:背景位置不同 Angular 偏移的困难

html - 时髦的 flexbox 高度

javascript - Bootstrap 固定表格单元格

javascript - 使用 css 的行编号段落

css - Twitter Bootstrap - 样式不会显示在移动浏览器上

internet-explorer - 强制 IE9 进入 Quirks 模式?

background-image - CSS 背景 : set position then do a shift?