CSS选择框箭头样式 [英] CSS Select box arrow style
问题描述
我要从选择框中删除默认箭头,并要使用自定义图标。从以前的答案,SO,我已经发现,这是不可能的(使它与主要浏览器工作)。只有可能性是将select包装在一个div中,并将其宽度设置为大于div宽度并设置overflow:hidden。
我试图关注,但它不工作。
code>< div class =selectParent>
< select>
< option value =1>选项1< / option>
< option value =2>选项2< / option>
< / select>
< / div>
CSS :
.selectParent {
width:80px;
overflow:hidden;
}
.selectParent select {
width:100px;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
padding:2px 30px 2px 2px;
border:none;
background:transparent url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png)no-repeat right center;
}
JSFiddle:
http://jsfiddle.net/gcPmC/
左侧
http://jsfiddle.net/afshinprofe/qhCsJ/1/
右侧
http://jsfiddle.net/afshinprofe/qhCsJ/3/
I want to remove the default arrow from the select box and want to use custom icon. From the previous answers on SO, I have found out that it is not possible (to make it work with major browsers). Only possibility is to wrap the select inside a div, and set its width more than the div width and setting overflow: hidden. I am trying following, but it does not work. What I'm doing wrong?
HTML:
<div class="selectParent">
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>
CSS:
.selectParent{
width:80px;
overflow:hidden;
}
.selectParent select{
width:100px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 2px 30px 2px 2px;
border: none;
background: transparent url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") no-repeat right center;
}
JSFiddle: http://jsfiddle.net/gcPmC/
check this out
left side
http://jsfiddle.net/afshinprofe/qhCsJ/1/
right side
http://jsfiddle.net/afshinprofe/qhCsJ/3/
这篇关于CSS选择框箭头样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!