前端开发-CSS 实现select

select下拉选择器在前端开发中很长用,但是其样式却受制于浏览器,不通的内核显示不通的效果,特别是在移动端,下拉选择往往不能统一。
实现效果:

这里写图片描述

图片2

这里写图片描述)

代码:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>js模拟select</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .selectBox {
            margin: 10px 0;

            line-height: 40px;
            width: 90%;
            margin-left: 5%;
            font-size: 14px;
            position: relative;
        }

        .selectHeader {
            border-bottom: 1px solid #cccccc;
            width: 88%;
            border: 1px solid #cccccc;
        }

        .selectContent {
            list-style-type: none;
            display: none;
            position: absolute;
            top: 42px;
            z-index: 2;
            background-color: white;
            width: 88%;
            border-left: 1px solid #cccccc;
            border-right: 1px solid #cccccc;
            left: 0px;
        }

        li {
            border-bottom: 1px solid #c4c6c7;
        }

        .content {
            padding-left: 5%;
        }

        .selectIcon {
            position: absolute;
            right: 1px;
            width: 11%;
            color: red;
            top: 0;
            border: 1px solid #cccccc;
            border-left: 0;
            text-align: center;
        }

        .selectIcon img {
            width: 15px;
            position: relative;
            top: 3px;
        }

        .selectIconUp {
            transform: rotate(180deg);
            -moz-transform: rotate(180deg); /* Firefox */
            -webkit-transform: rotate(180deg); /* Safari 和 Chrome */
            -o-transform: rotate(180deg);
        }
    </style>
</head>
<body>
<div class="selectBox">
    <div class="selectHeader"><span class="content">省份</span></div>
    <div class="selectIcon"><img src="image/selectIcon.png" class="selectIconUp"></div>
    <ul class="selectContent">
        <li><span class="content">北京</span></li>
        <li><span class="content">河北省</span></li>
        <li><span class="content">山东省</span></li>
    </ul>
</div>
<div style="word-wrap: break-word;padding: 0 5%;">
</div>
</body>
<script src="js/jquery.min.js"></script>
<script src="select.js"></script>
<script>
    $(".selectHeader,.selectIcon").click(function () {
        $(".selectIcon img").toggleClass("selectIconUp");
        $(".selectContent").toggle();
    });
    $("li").click(function () {
        var str = $(this).children().text();
        $(".selectHeader span").text(str);
        $(".selectContent").toggle();
    })
</script>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值