我正在尝试用我自己的照片替换选择的箭头。我包括选择在一个div与相同的大小,我设置的背景选择为透明,我包括一个图片(与箭头大小相同)在div的右上角作为背景。

它只适用于Chrome浏览器。

我如何让它在Firefox和IE9中工作,我得到了这个:

.styled-select { width: 100px; height: 17px; overflow: hidden; overflow: -moz-hidden-unscrollable; background: url(images/downarrow_blue.png) no-repeat right white; border: 2px double red; display: inline-block; position: relative; } .styled-select select { background: transparent; -webkit-appearance: none; width: 100px; font-size: 11px; border: 0; height: 17px; position: absolute; left: 0; top: 0; } body { background-color: #333333; color: #FFFFFF; } .block label { color: white; } <HTML> <HEAD> </HEAD> <BODY> <p/> <form action="/prepareUpdateCategoryList.do?forwardto=search"> <fieldset class="block" id="searchBlock"> <p> <label style="width:80px">Class</label> <div class="styled-select"> <select property="voucherCategoryClass"> <option value="0">Select </option> <option value="7382">steam </option> </select> </div> </p> </fieldset> </form> </BODY> </HTML>


当前回答

下面是一个优雅的修复,它使用span来显示值。

布局是这样的:

<div class="selectDiv">
   <span class="selectDefault"></span>
   <select name="txtCountry" class="selectBox">
      <option class="defualt-text">-- Select Country --</option>
      <option value="1">Abkhazia</option>
      <option value="2">Afghanistan</option>
   </select>
</div>

小提琴

其他回答

样式标签与CSS和使用指针事件:

<label>
<select>
   <option value="0">Zero</option>
   <option value="1">One</option>
</select>
</label>

相对CSS为

label:after {
    content:'\25BC';
    display:inline-block;
    color:#000;
    background-color:#fff;
    margin-left:-17px;   /* remove the damn :after space */
    pointer-events:none; /* let the click pass trough */
}

我只是在这里使用了一个向下箭头,但是你可以设置一个带有背景图像的块。这是一个丑陋的小提琴样本:https://jsfiddle.net/1rofzz89/

只要这样做:

select { background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNSIgaGVpZ2h0PSIyNSIgZmlsbD0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2U9IiNiYmIiPjxwYXRoIGQ9Ik02IDlsNiA2IDYtNiIvPjwvc3ZnPg==) !important; background-repeat: no-repeat !important; background-position-x: 100% !important; background-position-y: 50% !important; -webkit-appearance: none !important; -moz-appearance: none !important; -ms-appearance: none !important; -o-appearance: none !important; appearance: none !important; } select::-ms-expand { display: none; }

你有没有试过这样的方法:

.styled-select select {
    -moz-appearance:none; /* Firefox */
    -webkit-appearance:none; /* Safari and Chrome */
    appearance:none;
}

还没有测试,但应该工作。

编辑:Firefox似乎在35版之前都不支持这个功能(点击这里阅读更多)

这里有一个解决办法,看看那篇文章上的jsfiddle。

它可以在所有浏览器中工作:

select {
    width: 268px;
    padding: 5px;
    font-size: 16px;
    line-height: 1;
    border: 0;
    border-radius: 5px;
    height: 34px;
    background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right #ddd;
    appearance:none;
    -moz-appearance:none; /* Firefox */
    -webkit-appearance:none; /* Safari and Chrome */
    background-position-x: 244px;

}

好吧,这里似乎有很多答案。有些可能比其他的更好。如果有人绝望到想往下翻,这是我的意见:

如果你真的想要样式你的下拉菜单,不要使用<select>。在Div中使用常规的<ul>将会更加灵活。然而,如果你真的坚持使用select,因为你只是想要最小的下拉列表,这是我的:

select { appearance: none; background: white; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16px' height='16px' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6.1018 8C5.02785 8 4.45387 9.2649 5.16108 10.0731L10.6829 16.3838C11.3801 17.1806 12.6197 17.1806 13.3169 16.3838L18.8388 10.0731C19.5459 9.2649 18.972 8 17.898 8H6.1018Z' fill='%23212121'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.5rem center; border-radius: 2px; padding: 0.25rem 2rem 0.25rem 0.75rem; } <select> <option value="bottom-right">Bottom right</option> <option value="bottom-left">Bottom left</option> <option value="top-right">Top right</option> <option value="top-left">Top left</option> </select>

关键部分是找到一个插入符号svg,你可以把它URL转换成字符串。我可以稍微加强它,也许以某种方式旋转插入符号,但真的-我很高兴它不太丑。