How to remove the arrow from a select element in Firefox

后端 未结 30 1230
北恋
北恋 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:32

    Further to Joao Cunha's answer, this problem is now on Mozilla's ToDo List and is targeted for ver 35.

    For those desiring, here is a workaround by Todd Parker, referenced on Cunha's blog, that works today:

    http://jsfiddle.net/xvushd7x/

    HTML:

    
    

    CSS:

    /* Label styles: style as needed */
    label {
      display:block;
      margin-top:2em;
      font-size: 0.9em;
      color:#777;
    }
    
    /* Container used for styling the custom select, the buttom class below adds the bg gradient, corners, etc. */
    .custom-select {
      position: relative;
      display:block;
      margin-top:0.5em;
      padding:0;
    }
    
    /* These are the "theme" styles for our button applied via separate button class, style as you like */
    .button {
      border: 1px solid #bbb;
      border-radius: .3em;
      box-shadow: 0 1px 0 1px rgba(0,0,0,.04);
      background: #f3f3f3; /* Old browsers */
      background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%); /* FF3.6+ */
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e5e5e5)); /* Chrome,Safari4+ */
      background: -webkit-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Chrome10+,Safari5.1+ */
      background: -o-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Opera 11.10+ */
      background: -ms-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* IE10+ */
      background: linear-gradient(to bottom, #ffffff 0%,#e5e5e5 100%); /* W3C */
    }
    
    /* This is the native select, we're making everything but the text invisible so we can see the button styles in the wrapper */
    .custom-select select {
      width:100%;
      margin:0;
      background:none;
      border: 1px solid transparent;
      outline: none;
      /* Prefixed box-sizing rules necessary for older browsers */
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      /* Remove select styling */
      appearance: none;
      -webkit-appearance: none;
      /* Font size must the 16px or larger to prevent iOS page zoom on focus */
      font-size:16px;
      /* General select styles: change as needed */
      font-family: helvetica, sans-serif;
      font-weight: bold;
      color: #444;
      padding: .6em 1.9em .5em .8em;
      line-height:1.3;
    }
    
    
    /* Custom arrow sits on top of the select - could be an image, SVG, icon font, etc. or the arrow could just baked into the bg image on the select. Note this si a 2x image so it will look bad in browsers that don't support background-size. In production, you'd handle this resolution switch via media query but this is a demo. */
    
    .custom-select::after {
      content: "";
      position: absolute;
      width: 9px;
      height: 8px;
      top: 50%;
      right: 1em;
      margin-top:-4px;
      background-image: url(http://filamentgroup.com/files/select-arrow.png);
      background-repeat: no-repeat;
      background-size: 100%;
      z-index: 2;
      /* These hacks make the select behind the arrow clickable in some browsers */
      pointer-events:none;
    }
    
    
    /* Hover style */
    .custom-select:hover {
      border:1px solid #888;
    }
    
    /* Focus style */
    .custom-select select:focus {
      outline:none;
      box-shadow: 0 0 1px 3px rgba(180,222,250, 1);
      background-color:transparent;
      color: #222;
      border:1px solid #aaa;
    }
    
    /* Set options to normal weight */
    .custom-select option {
      font-weight:normal;
    }
    

提交回复
热议问题