php下拉框css样式,简单介绍CSS自定义下拉列表样式的示例代码分享

下拉列表的默认样式:

16af9d8b8d17962ac8201c524191bc99.png

下面介绍自定义下拉列表的两种方法:

方法一:

用纯CSS自定义下拉列表的样式。

原理:将默认的下拉列表样式清除,自定义样式,并附上一张向右对齐的小箭头图片。

select{

width:200px;

height:30px;

appearance:none;

-moz-appearance:none;

-webkit-appearance:none;

background: url("images/select.png") no-repeat right center;

font-size:16px;

font-family:Microsoft YaHei;

color:red;

}

请选择

北京

上海

广州

c5279c2f7a0fcd55e30389c62df4ffb3.png

问题:修改option的宽和高无效。

方法二:

用p+ul+jQuery实现自定义样式的下拉列表select。

7d63fc46ac9ad77a1706d8b71b472208.png

HTML代码:

  • 请选择
  • 北京
  • 上海
  • 广州

CSS代码:#container{

background:grey;

width:300px;

height:200px;

padding:20px;

}

form p{

width:236px;

height:34px;

}

form p{

font-family:Microsoft YaHei;

background:#FFFFFF;

}

form p:hover{

border:1px solid #E74F4D;

}

form ul{

margin:0;

padding:0;

}

form ul li:first-child{

height:34px;

line-height:34px;

}

form ul li{

width:236px;

height:24px;

line-height:24px;

font-size:15px;

color:#323333;

opacity:0.7;

background:#e3e3e5;

text-indent:12px;

display:none;

}

form ul li.active{

display:block;

background:url("images/arrows_active_down.gif") no-repeat scroll right center;

opacity:1;

}

form ul li:not(.active):hover{

background:#E74F4D;

color:white;

}

jQuery代码:$(document).ready(function(){

var p = $("form").find("p");

p.mouseover(function(e) {

var event = e || window.event;

var target = event.target || event.srcElement;

var _this = $(this);

if(target.nodeName.toLowerCase() == 'li') {

_this.find('li').css('display', 'block');

_this.find('li').click(function(){

var li = $(this);

_this.find('.active').text(li.text());

});

}

_this.mouseout(function(e) {

var event = e || window.event;

var target = event.target || event.srcElement;

if(target.nodeName.toLowerCase() == 'li')

_this.find('li').not('.active').css('display','none');

});

});

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值