如何从select元素中删除箭头

时间:2014-11-24 10:38:38

标签: css

以下CSS假设有效,但在FF(33.1.1)中,选择箭头仍然显示:

.select-style select {
    padding: 9px 8px 0 5px;
    width: 100%;
    border: none;
    font-size: 14px;
    box-shadow: none;
    background: transparent;
    background-image: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    text-indent: 0.01px;
    text-overflow: '';
}

http://jsfiddle.net/js25t1nx/1/

1 个答案:

答案 0 :(得分:1)

1)为自定义箭头图标添加一个伪元素,并将其放置在select元素的右侧,使其覆盖默认箭头。

2)在伪元素上设置pointer-events: none;,这样点击它就不会妨碍打开时的下拉。

<强> DEMO

.select-style:after {
    content: '';
    display: inline-block;
    width: 30px;
    height: 30px;
    background: #fafafa url("http://icons.iconarchive.com/icons/iconsmind/outline/128/Triangle-ArrowDown-icon.png") no-repeat 98% 4px;
    background-size: 26px 26px;
    position: absolute;
    right: 0;
    top: 0;
    pointer-events: none; /* <-- */
}

&#13;
&#13;
.select-style {
  border: 1px solid #333;
  width: auto;
  height: 32px;
  overflow: hidden;
  position: relative;
  margin: 40px;
}
.select-style:after {
  content: '';
  display: inline-block;
  width: 30px;
  height: 30px;
  background: #fafafa url("http://icons.iconarchive.com/icons/iconsmind/outline/128/Triangle-ArrowDown-icon.png") no-repeat 98% 4px;
  background-size: 26px 26px;
  position: absolute;
  right: 0;
  top: 0;
  pointer-events: none;
}
.select-style select {
  padding: 9px 8px 0 5px;
  width: 100%;
  border: none;
  font-size: 14px;
}
&#13;
<div class="select-style">

  <select>
    <option value="volvo">Please select an option</option>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </select>
&#13;
&#13;
&#13;