html select下拉框样式如何制作

发布时间:2020-09-26 14:52:52 作者:小新
来源:亿速云 阅读:932

这篇文章将为大家详细讲解有关html select下拉框样式如何制作,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

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

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

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

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

<!doctype html>
<html >
<head>
    <meta charset="UTF-8">
    <script type="js/index.js"></script>
    <title>亿速云之下拉列表</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>

这个我点开之后的效果图:

html select下拉框样式如何制作

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

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

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

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

<body>
        <br />
        <select id="selectTravelCity" title="Select Travel Destination">
            <option>亿速云</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>亿速云</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>

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

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

html select下拉框样式如何制作

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>

关于html select下拉框样式如何制作就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. html5的常用标签
  2. HTML表单(下)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

select option html

上一篇:html p标签添加br换行标签的应用

下一篇:html中frame标签的使用方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》