【问题标题】:How Can I hide the Default Arrow of Select Box and Set the desired Image?如何隐藏选择框的默认箭头并设置所需的图像?
【发布时间】:2014-08-31 15:43:16
【问题描述】:

我想要做的只是隐藏 HTML 表单元素的选择框的默认箭头,并将其替换为我想要的箭头,这是一个图像。我尝试了很多东西,但找不到适用于所有浏览器 IE、Firefox、Chrome 等的确切解决方案。这是我在这个问题中的代码:Can't set position of background in IE 10 or Less

因为没有人这么回答,这就是我再次询问的原因以及是否有人可以给我一个干净的代码。

谢谢,

如果您认为问题不好或解释不好,请在 cmets 中告诉我。

【问题讨论】:

  • 哇,这个问题有这么多糟糕的答案。

标签: html css


【解决方案1】:

这里是演示:http://www.tutorialrepublic.com/codelab.php?topic=faq&file=custom-select-box

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Custom Select Box with CSS and jQuery</title>
<style type="text/css">
    .select-wrapper{
        float: left;
        display: inline-block;
        border: 1px solid #d8d8d8;            
        background: url("../images/dropdown.png") no-repeat right center;
        cursor: pointer;
    }
    .select-wrapper, .select-wrapper select{
        width: 200px;
        height: 26px;
        line-height: 26px;
    }
    .select-wrapper:hover{
        background: url("../images/dropdown-hover.png") no-repeat right center;
        border-color: #239fdb;
    }
    .select-wrapper .holder{
        display: block;
        margin: 0 35px 0 5px;
        white-space: nowrap;            
        overflow: hidden;
        cursor: pointer;
        position: relative;
        z-index: -1;
    }
    .select-wrapper select{
        margin: 0;
        position: absolute;
        z-index: 2;            
        cursor: pointer;
        outline: none;
        opacity: 0;
        /* CSS hacks for older browsers */
        _noFocusLine: expression(this.hideFocus=true); 
        -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
        filter: alpha(opacity=0);
        -khtml-opacity: 0;
        -moz-opacity: 0;
    }

    /* Let's Beautify Our Form */
    form{
        margin: 20px;
    }
    input[type="submit"]{
        float: left;
        background: #d8d8d8;
        border: 1px solid #c4c4c4;
        margin-left: 10px;
        padding: 4px 10px;
        cursor: pointer;
        outline: none;
    }
    input[type="submit"]:hover{
        color: #fff;
        border-color: #1b7aa9;
        background-color: #239fdb;
    }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".custom-select").each(function(){
            $(this).wrap("<span class='select-wrapper'></span>");
            $(this).after("<span class='holder'></span>");
        });
        $(".custom-select").change(function(){
            var selectedOption = $(this).find(":selected").text();
            $(this).next(".holder").text(selectedOption);
        }).trigger('change');
    })
</script>
</head>
<body>
    <form action="../faq/select-action.php" method="post">
        <p>What Is Your Favourite Time Pass:</p>        
        <select name="timepass" class="custom-select">
            <option>Select</option>
            <option>Driving</option>
            <option>Internet</option>
            <option>Movie</option>
            <option>Music</option>
            <option>Reading</option>
            <option>Sports</option>                
        </select>
        <input type="submit" value="Submit">
    </form>
</body>
</html>                                     

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 2014-12-04
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 2021-03-09
    • 1970-01-01
    相关资源
    最近更新 更多