我正在尝试用我自己的照片替换选择的箭头。我包括选择在一个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>

小提琴

其他回答

这将工作得很好,特别是那些使用Bootstrap,在最新的浏览器版本测试:

select { -webkit-appearance: none; -moz-appearance: none; appearance: none; /* Some browsers will not display the caret when using calc, so we put the fallback first */ background: url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") white no-repeat 98.5% !important; /* !important used for overriding all other customisations */ background: url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") white no-repeat calc(100% - 10px) !important; /* Better placement regardless of input width */ } /*For IE*/ select::-ms-expand { display: none; } <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/> <div class="container"> <div class="row"> <div class="col-xs-6"> <select class="form-control"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> </div> </div> </div>

你也可以试试这个:

这里有一张它的照片!

并运行代码片段!

CSS和HTML:

#select-category { font-size: 100%; padding: 10px; padding-right: 180px; margin-left: 30px; border-radius: 1000000px; border: 1px solid #707070; outline: none; -webkit-appearance: none; -moz-appearance: none; background: transparent; background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='34' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>"); background-repeat: no-repeat; background-position-x: 100%; background-position-y: 5px; margin-right: 2rem; } <select id="select-category"> <option>Category</option> <option>Category 2</option> <option>Category 3</option> <option>Category 4</option> <option>Category 5</option> <option>Category 6</option> <option>Category 7</option> <option>Category 8</option> <option>Category 9</option> <option>Category 10</option> <option>Category 11</option> <option>Category 12</option> </select>

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

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

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

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

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

看看这个 这很俗气,很简单:

将-prefix-appearance设置为none以删除样式 使用文本缩进将内容向右“推”一点 最后,将text-overflow设置为空字符串。任何超出它宽度的东西都会变成…没有什么!包括箭头。

现在你可以自由地设置你想要的样式:)

.selectParent { width: 80px; overflow: hidden; } .selectParent select { text-indent: 1px; text-overflow: ''; width: 100px; -webkit-appearance: none; -moz-appearance: none; appearance: none; padding: 2px 2px 2px 2px; border: none; background: transparent url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") no-repeat 60px center; } <div class="selectParent"> <select> <option value="1">Option 1</option> <option value="2">Option 2</option> </select> </div>

查看JSFiddle

我已经提到了这篇文章,它像魅力一样工作,除了它没有隐藏在IE浏览器中的箭头。

但是添加以下会隐藏IE中的箭头:

&: -ms-expand { 显示:没有; }

完整解决方案(sass)

$select-border-color: #ccc; $select-focus-color: green; select { cursor: pointer; /* styling */ background-color: white; border: 1px solid $select-border-color; border-radius: 4px; display: inline-block; font: inherit; line-height: 1.5em; padding: 0.5em 3.5em 0.5em 1em; /* reset */ margin: 0; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; -webkit-appearance: none; -moz-appearance: none; background-image: linear-gradient(45deg, transparent 50%, $select-border-color 50%), linear-gradient(135deg, $select-border-color 50%, transparent 50%), linear-gradient(to right, $select-border-color, $select-border-color); background-position: calc(100% - 20px) calc(1em + 2px), calc(100% - 15px) calc(1em + 2px), calc(100% - 2.5em) 0.5em; background-size: 5px 5px, 5px 5px, 1px 1.5em; background-repeat: no-repeat; /* Very imp: hide arrow in IE */ &::-ms-expand { display: none; } &:-moz-focusring { color: transparent; text-shadow: none; } &:focus { background-image: linear-gradient(45deg, $select-focus-color 50%, transparent 50%), linear-gradient(135deg, transparent 50%, $select-focus-color 50%), linear-gradient(to right, $select-focus-color, $select-focus-color); background-position: calc(100% - 15px) 1em, calc(100% - 20px) 1em, calc(100% - 2.5em) 0.5em; background-size: 5px 5px, 5px 5px, 1px 1.5em; background-repeat: no-repeat; border-color: $select-focus-color; outline: 0; } }