How to remove the arrow from a select element in Firefox

后端 未结 30 1622
北恋
北恋 2020-11-22 15:58

I\'m trying to style a select element using CSS3. I\'m getting the results I desire in WebKit (Chrome / Safari), but Firefox isn\'t playing nicely (I\'m not ev

30条回答
  •  春和景丽
    2020-11-22 16:50

    I think I found the solution compatible with FF31!!!
    Here are two options that are well explained at this link:
    http://www.currelis.com/hiding-select-arrow-firefox-30.html

    I used option 1: Rodrigo-Ludgero posted this fix on Github, including an online demo. I tested this demo on Firefox 31.0 and it appears to be working correctly. Tested on Chrome and IE as well. Here is the html code:

    
    
        
        
        Custom Select
        
        
        
            

    and the css:

    .custom-select {
        background-color: #fff;
        border: 1px solid #ccc;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        margin: 0 0 2em;
        padding: 0;
        position: relative;
        width: 100%;
        z-index: 1;
    }
    
    .custom-select:hover {
        border-color: #999;
    }
    
    .custom-select:before {
        color: #333;
        display: block;
        font-family: 'FontAwesome';
        font-size: 1em;
        height: 100%;
        line-height: 2.5em;
        padding: 0 0.625em;
        position: absolute;
        top: 0;
        right: 0;
        text-align: center;
        width: 1em;
        z-index: -1;
    }
    
    .custom-select select {
        background-color: transparent;
        border: 0 none;
        box-shadow: none;
        color: #333;
        display: block;
        font-size: 100%;
        line-height: normal;
        margin: 0;
        padding: .5em;
        width: 100%;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
    
    .custom-select select::-ms-expand {
        display: none; /* to ie 10 */
    }
    
    .custom-select select:focus {
        outline: none;
    }
    /* little trick for custom select elements in mozilla firefox  17/06/2014 @rodrigoludgero */
    :-moz-any(.custom-select):before {
        background-color: #fff; /* this is necessary for overcome the caret default browser */
        pointer-events: none; 
        z-index: 1; /* this is necessary for overcome the pseudo element */
    }
    

    http://jsbin.com/pozomu/4/edit

    It works very good for me!

提交回复
热议问题