gpt4 book ai didi

html - CSS 选择框箭头样式

转载 作者:技术小花猫 更新时间:2023-10-29 12:02:27 26 4
gpt4 key购买 nike

我想从选择框中删除默认箭头并使用自定义图标。从之前关于 SO 的回答中,我发现这是不可能的(让它与主流浏览器一起工作)。唯一的可能性是将 select 包裹在一个 div 中,并将其宽度设置为大于 div 宽度并设置溢出:隐藏。我正在尝试关注,但它不起作用。我做错了什么?

.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;
}
<div class="selectParent">
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>

JSFiddle: http://jsfiddle.net/gcPmC/

最佳答案

请按照以下方式操作:

.selectParent {
width:120px;
overflow:hidden;
}
.selectParent select {
display: block;
width: 100%;
padding: 2px 25px 2px 2px;
border: none;
background: url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") right center no-repeat;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
}
.selectParent.left select {
direction: rtl;
padding: 2px 2px 2px 25px;
background-position: left center;
}
/* for IE and Edge */
select::-ms-expand {
display: none;
}
<div class="selectParent">
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>
<br />
<div class="selectParent left">
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>

关于html - CSS 选择框箭头样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12668404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com