我想从HTML <select>元素中删除下拉箭头。例如:
<select style="width:30px;-webkit-appearance: none;">
<option>2000</option>
<option>2001</option>
<option>2002</option>
...
</select>
在Opera、Firefox和ie浏览器中如何做到这一点?
我想从HTML <select>元素中删除下拉箭头。例如:
<select style="width:30px;-webkit-appearance: none;">
<option>2000</option>
<option>2001</option>
<option>2002</option>
...
</select>
在Opera、Firefox和ie浏览器中如何做到这一点?
当前回答
如果你使用TailwindCSS 您可以利用无外观类。
<select class="appearance-none">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</select>
其他回答
试试这个:
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 2px 30px 2px 2px;
border: none;
}
JS Bin: http://jsbin.com/aniyu4/2/edit
如果你使用Internet Explorer:
select {
overflow:hidden;
width: 120%;
}
或者你可以使用Choosen: http://harvesthq.github.io/chosen/
试试这个:
HTML:
<div class="customselect">
<select>
<option>2000</option>
<option>2001</option>
<option>2002</option>
</select>
</div>
CSS:
.customselect {
width: 70px;
overflow: hidden;
}
.customselect select {
width: 100px;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
}
只是想把这个话题讲完。 很明显,这在IE9中是行不通的,但是我们可以通过一些css技巧来实现。
<div class="customselect">
<select>
<option>2000</option>
<option>2001</option>
<option>2002</option>
</select>
</div>
.customselect {
width: 80px;
overflow: hidden;
border:1px solid;
}
.customselect select {
width: 100px;
border:none;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
}
如果你使用TailwindCSS 您可以利用无外观类。
<select class="appearance-none">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</select>
前面提到的解决方案适用于chrome,但不适用于Firefox。
我发现了一个解决方案,在Chrome和Firefox(不是IE)都很好。将以下属性添加到SELECTelement的CSS中,并根据需要调整margin-top。
选择{ -webkit-appearance:没有; -moz-appearance:没有; indent: 1 px; 文本溢出:“; } <选择> <选项> > < /选项之一 <选项> < /两个选项> <选项> 3 < /选项> < /选择>