我正在尝试创建自定义下拉控件,我需要隐藏本机控件中的箭头。我使用的是以下CSS
,适用于Chrome和Safari,但不适用于Mozilla和IE。
select.desktopDropDown
{
appearance: none;
-moz-appearance:none; /* Firefox */
-webkit-appearance:none; /* Safari and Chrome */
}
这是[jsfiddle] [1]。
答案 0 :(得分:69)
使用它可以使用IE10 +和FF:
你的CSS应该是这样的:
select.desktopDropDown::-ms-expand {
display: none;
}
有关::ms-expand
的更多信息。
然后是其余的:
select.desktopDropDown {
outline : none;
overflow : hidden;
text-indent : 0.01px;
text-overflow : '';
background : url("../img/assets/arrow.png") no-repeat right #666;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
}
注意:我将路径"../img/assets/arrow.png"
硬编码为背景。
这在IE,Firefox和Opera中应该对你有用。
答案 1 :(得分:19)
Bare-bones示例:
select::-ms-expand {
display: none;
}
select {
-moz-appearance: none;
appearance: none;
text-overflow: ''; /* this is important! */
}
答案 2 :(得分:3)
对于Fx,我使用-moz-appearance: checkbox-container
,效果很好。
所以将以下内容放在一起对您来说应该足够了:
select.desktopDropDown {
appearance: none;
-webkit-appearance: none;
-moz-appearance: checkbox-container;
border-style: none;
}
select.desktopDropDown::-ms-expand {
display: none;
}
答案 3 :(得分:2)
实际上这个技巧主要用于IE10 +,其中箭头是Windows 8的Metro风格,即使在Windows 7上也是如此。虽然Windows 8用户必须习惯这种风格,因为它通过操作系统使用。无论如何,我建议不要使用:
display: none;
使用:
visibility: hidden;
因为,至少在IE中,前者会导致所选项目的蓝线在选择聚焦时覆盖下拉箭头,而后者则不会。
答案 4 :(得分:0)
我们可以使用css创建自定义。在IE10,Mozilla和chrome borwser上测试...
工作实例如下:
.customSelect {
position: relative;
}
/* IE11 hide hacks*/
select::-ms-expand {
display: none;
}
.customSelect:after {
content: '<>';
font: 17px "Consolas", monospace;
color: #333;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
right: 11px;
/*Adjust for position however you want*/
top: 18px;
padding: 0 0 2px;
border-bottom: 1px solid #999;
/*left line */
position: absolute;
pointer-events: none;
}
.customSelect select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* Add some styling */
display: block;
width: 100%;
height: 50px;
float: none;
margin: 5px 0px;
padding: 0px 24px;
font-size: 16px;
line-height: 1.75;
color: #333;
background-color: #ffffff;
background-image: none;
border: 1px solid #cccccc;
-ms-word-break: normal;
word-break: normal;
}
&#13;
<div class="customSelect">
<label>
<select>
<option selected> Select Box </option>
<option>Option 1</option>
<option>Option 2</option>
<option>Last long option</option>
</select>
</label>
</div>
&#13;