视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
基于jquery实现下拉框美化特效_jquery
2020-11-27 20:50:27 责编:小采
文档
 平常我们用的原生select下拉框,大部分样式没办法修改,导致在不同的浏览器里面会跟设计图的风格大相径庭。所以为了能让它美化起来,就用JQ模拟了一个下拉框,可以随意定义样式。原生的下拉框也保留在div里面隐藏着,方便后台开发人员对其进行操作。

效果图如下:

HTML代码如下:




 
 下拉框美化
 
 
 
 

CSS样式如下:

@charset "utf-8";
/* 简单reset */
body, ul, li {
 margin: 0;
 padding: 0;
}
body {
 font: 14px/24px Microsoft YaHei;
 color: #333;
}
ul { list-style: none; }
a {
 color: #333;
 outline: none;
 text-decoration: none;
}
table {
 border-collapse: collapse;
 border-spacing: 0;
 text-align: left;
}
/* 布局样式,非必须 */
.wrap {
 width: 600px;
 margin: 100px auto 0;
 padding: 20px;
 background-color: #d3f3dd;
}
.wrap table th, .wrap table td { padding: 8px 2px; }
.wrap table th {
 font-weight: normal;
 text-align: right;
}
/* 下拉框样式 必须 */
.select-style ul {
 list-style: none;
 padding: 0;
 margin: 0;
}
.select-style select { display: none; }
.select-style {
 position: relative;
 display: inline-block;
 font-family: Microsoft YaHei;
 color: #666;
 font-size: 14px;
 text-align: left;
 vertical-align: middle;
 z-index: 50;
}
.select-style.focus { z-index: 51; }
.select-style .slt-wrap {
 display: inline-block;
 width: 200px;
 border: solid 1px #d6d6d6;
 vertical-align: middle;
}
.select-style.focus .slt-wrap { border: solid 1px #53a8df; }
.select-style .slt-title {
 position: relative;
 display: block;
 padding: 0 36px 0 5px;
 line-height: 30px;
 height: 30px;
 text-decoration: none;
 background-color: #fff;
 word-break: break-all;
 color: #666;
 overflow: hidden;
}
.select-style .slt-title .slt-text {
 display: inline-block;
 height: 30px;
 *cursor: pointer;
}
.select-style .slt-title i {
 position: absolute;
 right: 0;
 top: 0;
 display: inline-block;
 width: 30px;
 height: 30px;
 background: url(../images/ico-select.png) 0 0 no-repeat;
 *cursor: pointer;
}
.select-style.focus .slt-title i { background-position: 0 -30px; }
.select-style.disabled .slt-title i { 
 background-position: 0 -60px;
 *cursor: default; 
}
.select-style .opn-box {
 display: none;
 position: absolute;
 left: 0;
 top: 31px;
 width: 100%;
}
.select-style.up .opn-box {
 top: auto;
 bottom: 31px;
}
.select-style .opn-box .opn-list {
 position: relative;
 _width: 100%;
 max-height: 130px;
 border: 1px solid #d6d6d6;
 background: #fff;
 overflow-y: auto;
 overflow-x: hidden;
}
.select-style.focus .opn-box .opn-list { border-color: #53a8df; }
.select-style .opn-box .opn-list li {
 display: block;
 _width: 100%;
 padding-left: 5px;
 line-height: 26px;
 height: 26px;
 overflow: hidden;
 white-space: nowrap;
 text-overflow: ellipsis;
 cursor: pointer;
}
.select-style .opn-box .opn-list .selected { background: #d4edfe; }
.select-style .opn-box .opn-list li:hover {
 color: #fff;
 background: #65abda;
}
.select-style .opn-box .opn-list li.disabled {
 color: #cacaca;
 background: #f0f0f0;
 cursor: default;
}
.select-style.disabled .slt-wrap { border: 1px solid #d6d6d6; }
.select-style.disabled .slt-title {
 color: #cacaca;
 background-color: #f0f0f0;
 cursor: default;
}
.select-style.disabled .slt-title .slt-text { *cursor: default; }
/* 下拉框样式 结束 */

Jquery代码如下:



兼容到IE7+(IE6其实也行,只是选项多于5个下面不会出现滚动条)。

下载本文
显示全文
专题