CSS怎么去掉select的下拉箭头样式
2016-11-11 · 百度知道合伙人官方认证企业
css是无法去掉默认select的下拉箭头的,除非自己用div+js+css实现自定义select控件。
1、定义html中的select标签
<form>
<a class="btn-select" id="btn_select">
<span class="cur-select">请选择</span>
<select>
<option>选项一</option>
<option>选项二</option>
<option>选项三</option>
<option>选项四</option>
<option>选项五</option>
</select>
</a>
</form>
2、定义css样式:
* {
margin: 0;
padding: 0;
}
body {
padding: 50px 50px;
}
.btn-select {
position: relative;
display: inline-block;
width: 150px;
height: 25px;
background-color: #f80;
font: 14px/20px "Microsoft YaHei";
color: #fff;
}
.btn-select .cur-select {
position: absolute;
display: block;
width: 150px;
height: 25px;
line-height: 25px;
background: #f80 url(ico.png) no-repeat 125px center;
text-indent: 10px;
}
.btn-select:hover .cur-select {
background-color: #f90;
}
.btn-select select {
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 25px;
opacity: 0;
filter: alpha(opacity: 0;);
font: 14px/20px "Microsoft YaHei";
color: #f80;
}
.btn-select select option {
text-indent: 10px;
}
.btn-select select option:hover {
background-color: #f80;
color: #fff;
}
3、定义点击事件JS:
var $$ = function (id) {
return document.getElementById(id);
}
window.onload = function () {
var btnSelect = $$("btn_select");
var curSelect = btnSelect.getElementsByTagName("span")[0];
var oSelect = btnSelect.getElementsByTagName("select")[0];
var aOption = btnSelect.getElementsByTagName("option");
oSelect.onchange = function () {
var text=oSelect.options[oSelect.selectedIndex].text;
curSelect.innerHTML = text;
}
}
4、最终效果:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.styled-select {
width: 240px;
height: 34px;
overflow: hidden;
}
.styled-select select {
background: transparent;
width: 268px;
padding: 5px;
font-size: 16px;
border: 1px solid #ccc;
height: 34px;
-webkit-appearance: none; /*for chrome*/
}
</style>
</head>
<body>
<div class="styled-select">
<select name="citylist">
<option value="0">北京</option>
<option value="1">上海</option>
<option value="2">深圳</option>
<option value="3">广州</option>
</select>
</div>
</body>
</html>