浅谈CSS自定义下拉列表的样式
来源:互联网 发布:淘宝店铺id在哪里看 编辑:程序博客网 时间:2024/04/29 06:51
下拉列表的默认样式:
下面介绍自定义下拉列表的两种方法:
方法一:
用纯CSS自定义下拉列表的样式。
原理:将默认的下拉列表样式清除,自定义样式,并附上一张向右对齐的小箭头图片。
<!doctype html><html><head><style type="text/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;}</style></head><body><form action="" method="post"><select><option value="请选择">请选择</option><option value="北京">北京</option><option value="上海">上海</option><option value="广州">广州</option></select></form></body></html>
问题:修改option的宽和高无效。
方法二:
用div+ul+jQuery实现自定义样式的下拉列表select。
HTML代码:
<div id="container"><form action="" method="post"><div><ul><li class="active">请选择</li><li>北京</li><li>上海</li><li>广州</li></ul></div></form></div>
CSS代码:
#container{background:grey;width:300px;height:200px;padding:20px;}form div{ width:236px; height:34px;}form div{font-family:Microsoft YaHei; background:#FFFFFF;}form div: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 div = $("form").find("div"); div.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'); }); });});
1 0
- 浅谈CSS自定义下拉列表的样式
- CSS 自定义列表样式
- 自定义Spinner下拉列表样式
- 下拉列表的样式
- 漂亮的下拉列表 select样式 css处理 特效
- css改变下拉列表select框的默认样式
- 修改下拉列表<select>的默认css样式
- 纯css修改下拉列表select的默认样式
- 纯css来改变下拉列表框的样式。
- 下拉列表-select样式css处理
- android自定义Spinner下拉列表框样式
- 漂亮的下拉列表样式
- css 实现自定义下拉框样式
- css下拉框select自定义样式
- android自定义Spinner下拉菜单和AutoCompleteTextView自动显示的(下拉列表框)样式
- android自定义Spinner下拉菜单和AutoCompleteTextView自动显示的(下拉列表框)样式
- android自定义Spinner下拉菜单(下拉列表框)样式
- android自定义Spinner下拉菜单(下拉列表框)样式
- 编写程序:随机生成一个5位以上的数,将生成数的各位数字重新排列成一个与原整数相同的最小整数
- MS Com注册表信息及其注册过程
- 其他
- jQuery中对同一个元素使用mouseover和mouseout产生闪烁问题
- 网络编程中的粘包处理
- 浅谈CSS自定义下拉列表的样式
- 最优化复习要点
- 一起talk C栗子吧(第一百九十三回:C语言实例--DIY less命令二 )
- LeetCode 167. Two Sum II - Input array is sorted
- 线性回归 numpy normal equation & tensorflow gradient descent
- javaSE 基础总结
- 缓存一致性
- 小白学《神经网络与深度学习》笔记之二-利用稀疏编码器找图像的基本单位(1)MatLab实现SparseAutoEncoder
- leet24