html自定义select样式,自定义select样式

我们在做移动端时,select在ios和android下的样式不是自己想要的,我们可以定义自己的样式

元素

所在省:

请选择

新疆维吾尔族自治区

宁夏回族自治区

样式

.vertilist {

padding-left:15px;

}

.vertilist .vertilist-item {

padding: 10px 15px 10px 0px;

border-bottom: 1px solid #e6e6e6;

}

.selectwrap {

display: flex;

}

.selectwrap .tit {

min-width: 80px;

height: 30px;

line-height: 30px;

font-size: 16px;

font-weight: normal;

color:#666;

}

.selectwrap .selectval {

flex: 1;

position: relative;

}

.selectwrap .selectval:after {

content:'';

position: absolute;

top:12px; right:0;

border-left: 5px solid transparent;

border-right: 5px solid transparent;

border-top: 5px solid #ddd;

}

.selectwrap .selectval .value {

position: absolute;

top: 0;

right: 0;

padding-right: 20px;

width: 100%;

height: 30px;

line-height: 30px;

text-align: right;

font-size: 16px;

color:#666;

}

.selectwrap .selectval select {

position: absolute;

top: 10px;

width: 100%;

border: 0;

outline: none;

-webkit-appearance:none;/* 去除系统默认appearance的样式,常用于IOS下移除原生样式 */

opacity: 0;

font-size: 16px;

color: #666;

}

控制切换的值

$(".vertilist").on("change","select",function(){

$(this).prev(".value").text($(this).find('option:selected').text());

});