时间:2021-07-01 10:21:17 帮助过:42人阅读
CSS:
.p-select { border: solid 1px #999; height: 40px; line-height: 40px; cursor: default; } .p-select-text { float: left; background-color: #fff; height: 100%; word-break: keep-all; overflow: hidden; cursor: default; } .p-select-text > p { padding: 3px; line-height: 34px; } .p-select-arrow { background-color: #fff; float: right; width: 40px; height: 100%; color: #999; cursor: default; } .p-select-arrow > p { border: solid 1px #999; margin: 2px; height: 34px; background-color: #f2f2f2; text-align: center; line-height: 34px; font-size: 22px; } .p-select-list { position: absolute; float: left; top: 100px; left: 100px; border: solid 1px #999; max-height: 300px; overflow: auto; background-color: #9f9; display: none; z-index: 9100; } .p-select-list .p-select-item:nth-child(2n+1) { background-color: #fff; } .p-select-item { height: 50px; line-height: 50px; padding-left: 3px; padding-right: 3px; background-color: #f2f2f2; word-break: keep-all; overflow: hidden; cursor: default; } .p-select-item-hover { background-color: #3399ff!important; } .p-select-selected { background-color: #3399ff !important; }
JS:
如何使用:
第1步、引用CSS和JS:
<link type="text/css" href="~/scripts/pSelect/pSelect.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" /> <script type="text/javascript" src="~/scripts/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="~/scripts/pSelect/pSelect.js"></script>
第2步、给select控件加上class="p-select-target" width="200",其中class="p-select-target"是必须的,width="200"是可选的。完整HTML代码如下:
<link type="text/css" href="~/scripts/pSelect/pSelect.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" /> <script type="text/javascript" src="~/scripts/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="~/scripts/pSelect/pSelect.js"></script> <p style="border: solid 1px #f99; margin: 50px; padding: 50px;"> <select name="sel" class="p-select-target" width="200" > <option value="1">中国</option> <option value="2">美国</option> <option value="3">法国</option> <option value="4">英国</option> <option value="5">俄罗斯</option> <option value="6">德国</option> <option value="7">韩国</option> <option value="8">日本</option> <option value="9">印度</option> <option value="10">巴西</option> <option value="11">意大利</option> <option value="12">这个国家的名称很长很长很长很长很长很长很长很长</option> <option value="13">瑞士</option> <option value="14">越南</option> <option value="15">缅甸</option> <option value="16">泰国</option> <option value="17">加拿大</option> <option value="18" selected="selected">南非</option> <option value="19">澳大利亚</option> <option value="20">新西兰</option> <option value="21">挪威</option> <option value="22">巴勒斯坦</option> <option value="23">以色列</option> <option value="24">新加坡</option> <option value="25">马来西亚</option> <option value="26">波兰</option> <option value="27">国家27</option> <option value="28">国家28</option> <option value="29">国家29</option> <option value="30">国家30</option> <option value="31">国家31</option> <option value="32">国家32</option> <option value="33">国家33</option> <option value="34">国家34</option> <option value="35">国家35</option> <option value="36">国家36</option> <option value="37">国家37</option> <option value="38">国家38</option> </select> </p> <p style="border: solid 1px #f99; margin: 50px; padding: 50px; margin-top: 700px; margin-bottom: 700px;"> <select name="sel" class="p-select-target" width="200" > <option value="1">中国</option> <option value="2">美国</option> <option value="3">法国</option> <option value="4">英国</option> <option value="5">俄罗斯</option> <option value="6" selected="selected">德国</option> <option value="7">韩国</option> <option value="8">日本</option> </select> </p>
效果图:
滚动条美化版:
CSS:
.p-select { border: solid 1px #999; height: 40px; line-height: 40px; cursor: default; } .p-select-text { float: left; background-color: #fff; height: 100%; word-break: keep-all; overflow: hidden; cursor: default; font-size: 16px; font-family: 微软雅黑,雅黑; } .p-select-text > p { padding: 3px; line-height: 34px; } .p-select-arrow { background-color: #fff; float: right; width: 40px; height: 100%; color: #999; cursor: default; } .p-select-arrow > p { border: solid 1px #999; margin: 2px; height: 34px; background-color: #f2f2f2; text-align: center; line-height: 34px; font-size: 22px; } .p-select-list { position: absolute; float: left; top: 100px; left: 100px; border: solid 1px #999; max-height: 300px; overflow: hidden; background-color: #9f9; display: none; z-index: 9100; font-size: 16px; font-family: 微软雅黑,雅黑; } .p-select-list .p-select-item:nth-child(2n+1) { background-color: #fff; } .p-select-item { height: 50px; line-height: 50px; padding-left: 3px; padding-right: 3px; background-color: #f2f2f2; word-break: keep-all; overflow: hidden; cursor: default; } .p-select-item-hover { background-color: #3399ff!important; } .p-select-selected { background-color: #3399ff !important; } .p-select-list-scrollbar { position: absolute; float: left; border: solid 1px #999; border-left: 0; background-color: #e8e8ec; width: 40px; height: 300px; display: none; cursor: default; z-index: 9101; } .p-select-scrollbar-up { border-bottom: solid 1px #fff; height: 39px; font-size: 22px; line-height: 39px; color: #999; background-color: #cdcdcd; text-align: center; } .p-select-scrollbar-pos { height: 220px; } .p-select-scrollbar-pos > p:last-child { width: 40px; height: 20px; background-color: #cdcdcd; } .p-select-scrollbar-down { border-top: solid 1px #fff; height: 39px; font-size: 22px; line-height: 39px; color: #999; background-color: #cdcdcd; text-align: center; }
JS:
效果图:
以上就是HTML的select控件美化功能的详细内容,更多请关注Gxl网其它相关文章!