首先我们先来看看htmlselect下拉框样式的制作:
原生的select下拉框其实挺方便的,直接把选项写入option就能得到一个流畅的下拉框,但是原生的样式也是让人忧愁。
首先,在各大浏览器中渲染出来的样式结果也是多样化,ie下的样式更是与众不同,会根据选项位置进行滑动。
我们这里是用纯HTML制作,连层叠样式表也不要:
<!doctypehtml>
<html>
<head>
<metacharset="UTF-8">
<scripttype="js/index.js"></script>
<title>php中文网之下拉列表</title>
</head>
<body>
<form>
<p>下拉列表</p>
<select>
<option>html</option>
<option>php</option>
<option>python</option>
<option>其它</option>
<option>html</option>
<option>php</option>
<option>python</option>
<option>其它</option>
</select>
</form>
</body>
</html>
这个我点开之后的效果图:
tuyi.png
我们已经把HTMLselect的下拉框已经制作完成了,接下来我们看看HTMLselect的其它样式思路:
1.先去掉select本身原有的样式。
2.用一个元素(div/lebal等)作为select的父元素。
3.在select父元素后面用:after做一个新的样式。
<body>
<br/>
<selectid="selectTravelCity"title="SelectTravelDestination">
<option>php中文网</option>
<option>WashingtonDC</option>
<option>LosAngeles</option>
<option>Chicago</option>
<option>Houston</option>
<option>Philadelphia</option>
<option>Phoenix</option>
</select>
<br/>
<br/>
<labelid="lblSelect">
<selectid="selectPointOfInterest"title="Selectpointsofinterestnearby">
<option>PHP中文网</option>
<option>foodbeverage</option>
<option>restaurant</option>
<option>shopping</option>
<option>taxilimo</option>
<option>theatre</option>
<option>museum</option>
<option>computers</option>
</select>
</label>
</body>
这么多,虽然不是很难,但是还是要多练习的
看了上面的图片,这个的效果图也很容易能想到吧,不过我还是会给效果图的:
tuer.png
HTMLselect标签的两个案例分析:
案例一:如何让html里的select无法选择?
假设有一个select,里面有几个option,因为测试需要,要固定成为其中的一个option,不能选择其他,该怎么做呢?如果disabled这个select,结果就是根本没法取到值了。有没其他的方法?readonly,也是不可以的,依旧可以选择。
答案:只放一个option就可以了或者给option加上disabled="disabled"
<formid="form1"name="form1"method="post"action="">
<selectname="select">
<option>aa</option>
<optiondisabled="disabled">bb</option>
<option>cc</option>
</select>
</form>
案例二:怎么调整select的宽度?
答案:可以在select标签中加入style样式
<style>.s1{width:200px;}</style>
<selectclass="s1">
<OPTION>很长很长也能显示</OPTION>
<OPTION>很长很长也能显示</OPTION>
</select>
以上就是这篇文章的全部内容了,有什么疑问欢迎在下方提问。


本文转载自中文网

本文转载自中文网
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html5/h54772.shtml