Default style for drop-down list:
Here are two ways to customize a drop-down list:
Method One:
Customize the style of the drop-down list with a pure CSS.
Principle: Clears the Default drop-down list style, customizes the style, and attaches a small arrow right-aligned picture.
<!doctype html>
Problem: Modify the width and height of option to be invalid.
Method Two:
Use P+ul+jquery to implement a custom style drop-down list select.
HTML code:
<p id= "container" ><form action= "" method= "post" ><p><ul><li class= "active" > Please select </li ><li> Beijing </li><li> Shanghai </li><li> Guangzhou </li></ul></p></form> </p>
CSS code:
#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 Code:
$ (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 '); }); });});