星空网 > 软件开发 > 网页设计

用纯css改变下拉列表select框的默认样式

将浏览器默认的下拉框样式清除,然后应用上自己的,再附一张向右对齐小箭头的图片即可。

 1 select { 2 /*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/ 3  border: solid 1px #000; 4  5 /*很关键:将默认的select选择框样式清除*/ 6  appearance:none; 7  -moz-appearance:none; 8  -webkit-appearance:none; 9 /*在选择框的最右侧中间显示小箭头图片*/10  background: url("http://ourjs.github.io/static/2015/arrow.png") no-repeat scroll right center transparent;11 /*为下拉小箭头留出一点位置,避免被文字覆盖*/12  padding-right: 14px;13 }14 /*清除ie的默认选择框样式清除,隐藏下拉箭头*/15 select::-ms-expand { display: none; }

IE8/9并不支持  appearance:none  CSS属性,想要支持的话可能需要非常特殊的方法,参考SF: 我们需要为其添加一个父容器,容器是用来覆盖小箭头的,然后为select添加一个向右的小偏移或者宽度大于父级元素。设置父级的CSS属性为超出部分不可见,即可覆盖即小箭头。然后再为父级容器添加背景图片即可。

1 <div id="parent">2  <select>3    <option>what</option>4    <option>the</option>5    <option>hell</option>6  </select>7 </div>

1 #parent {background: url('yourimage') no-repeat; width: 100px;2 height: 30px; overflow: hidden;}3 #parent select {background: transparent; border: none; padding-left: 10px; width: 120px; height: 100%;}

 




原标题:用纯css改变下拉列表select框的默认样式

关键词:CSS

CSS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

黑五销售额:https://www.goluckyvip.com/tag/3741.html
立陶宛fba物流:https://www.goluckyvip.com/tag/37410.html
立陶宛专线:https://www.goluckyvip.com/tag/37411.html
立通达COD系统:https://www.goluckyvip.com/tag/37412.html
立赢德国海外仓:https://www.goluckyvip.com/tag/37413.html
丽水综试区:https://www.goluckyvip.com/tag/37414.html
夹江千佛岩景区门票(夹江千佛岩景区门票价格):https://www.vstour.cn/a/411232.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流