PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

html select下拉框样式怎么制作?html select样式详解

寻∝梦
寻∝梦 原创
2018-08-30 11:32:56 14343浏览

本篇文章主要的介绍了关于HTML select标签的下拉框制作,还有HTML select标签的样式解析,最后还有两个html select标签的案例。接下来让我们一起看看本篇文章吧

首先我们先来看看html select下拉框样式的制作:

原生的select下拉框其实挺方便的,直接把选项写入option就能得到一个流畅的下拉框,但是原生的样式也是让人忧愁。

首先,在各大浏览器中渲染出来的样式结果也是多样化,ie下的样式更是与众不同,会根据选项位置进行滑动。

我们这里是用纯HTML制作,连层叠样式表也不要:

<!doctype html>
<html >
<head>
    <meta charset="UTF-8">
    <script type="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

我们已经把HTML select的下拉框已经制作完成了,接下来我们看看HTML select的其它样式思路:

1.先去掉select本身原有的样式。

2.用一个元素(div/lebal等)作为select的父元素。

3.在select父元素后面用:after做一个新的样式。

<body>
        <br />
        <select id="selectTravelCity" title="Select Travel Destination">
            <option>php中文网</option>
            <option>Washington DC</option>
            <option>Los Angeles</option>
            <option>Chicago</option>
            <option>Houston</option>
            <option>Philadelphia</option>
            <option>Phoenix</option>
        </select>
        <br />
        <br />
        <label id="lblSelect">
            <select id="selectPointOfInterest" title="Select points of interest nearby">
                <option>PHP中文网</option>
                <option>food beverage</option>
                <option>restaurant</option>
                <option>shopping</option>
                <option>taxi limo</option>
                <option>theatre</option>
                <option>museum</option>
                <option>computers</option>
            </select>
        </label>
</body>

这么多,虽然不是很难,但是还是要多练习的

看了上面的图片,这个的效果图也很容易能想到吧,不过我还是会给效果图的:

tuer.png

HTML select标签的两个案例分析:

案例一:如何让html里的select无法选择?

假设有一个select,里面有几个option,因为测试需要,要固定成为其中的一个option,不能选择其他,该怎么做呢?如果disabled这个select,结果就是根本没法取到值了。有没其他的方法?readonly,也是不可以的,依旧可以选择。

答案:只放一个option就可以了 或者给option加上disabled="disabled"

<form id="form1" name="form1" method="post" action="">
  <select name="select">
    <option>aa</option>
<option disabled="disabled">bb</option>
<option>cc</option>
  </select>
</form>

案例二:怎么调整select的宽度?

答案:可以在select标签中加入style样式

<style>.s1{ width: 200px;}</style>
<select class="s1">
  <OPTION>很长很长也能显示</OPTION>
  <OPTION>很长很长也能显示</OPTION>
</select>

以上就是这篇文章的全部内容了,有什么疑问欢迎在下方提问。

【小编推荐】

html5 canvas标签是什么意思?canvas标签使用方法介绍

HTML中插入文本ins标签和删除文本del标签如何一起使用?(附实例)

以上就是html select下拉框样式怎么制作?html select样式详解的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。