Bootstrap 3 Styled Select dropdown looks ugly in Firefox on OS X

前端 未结 12 2107
小蘑菇
小蘑菇 2021-01-30 00:42

When styling a form

提交评论

  • 2021-01-30 01:11

    Building on the excellent answers by rafx and Sina, here is a snippet that only targets Firefox and replaces the default button with a down-caret copied from Bootstrap's icon theme.

    Before:

    After:

    @-moz-document url-prefix() {
      select.form-control {
        padding-right: 25px;
        background-image: url("data:image/svg+xml,\
          <svg version='1.1' xmlns='http://www.w3.org/2000/svg' width='14px'\
               height='14px' viewBox='0 0 1200 1000' fill='rgb(51,51,51)'>\
            <path d='M1100 411l-198 -199l-353 353l-353 -353l-197 199l551 551z'/>\
          </svg>");
        background-repeat: no-repeat;
        background-position: calc(100% - 7px) 50%;
        -moz-appearance: none;
        appearance: none;
      }
    }
    

    (The inline SVG has backslashes and newlines for readability. Remove them if they cause trouble in your asset pipeline.)

    Here is the JSFiddle

    0 讨论(0)
  • 2021-01-30 01:11

    This is the normal behavior, and it's caused by the default <select> style under Firefox : you can't set line-height, then you need to play on padding when you want to have a customized <select>.

    Example, with results under Firefox 25 / Chrome 31 / IE 10 :

    <select>
      <option>Default</option>
      <option>Default</option>
      <option>Default</option>
    </select>
    
    <select class="form-control">
      <option>Bootstrap</option>
      <option>Bootstrap</option>
      <option>Bootstrap</option>
    </select>
    
    <select class="form-control custom">
      <option>Custom</option>
      <option>Custom</option>
      <option>Custom</option>
    </select>
    
    select.custom {
      padding: 0px;
    }
    

    Bootply

    enter image description here

    0 讨论(0)
  • 2021-01-30 01:14

    Actualy you can do almost everything with dropdown field, and it will looks the same on every browser, take a look at code example

    select.custom {
      background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%20fill%3D%22%23555555%22%20%0A%09%20width%3D%2224px%22%20height%3D%2224px%22%20viewBox%3D%22-261%20145.2%2024%2024%22%20style%3D%22enable-background%3Anew%20-261%20145.2%2024%2024%3B%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20d%3D%22M-245.3%2C156.1l-3.6-6.5l-3.7%2C6.5%20M-252.7%2C159l3.7%2C6.5l3.6-6.5%22%2F%3E%0A%3C%2Fsvg%3E");
      padding-right: 25px;
      background-repeat: no-repeat;
      background-position: right center;
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
    }
    
    select.custom::-ms-expand {
      display: none;
    }
    

    https://jsfiddle.net/x76j455z/10/

    0 讨论(0)
  • 2021-01-30 01:14

    There is a slick-looking jQuery plugin that apparently plays nice with Bootstrap called SelectBoxIt (http://gregfranko.com/jquery.selectBoxIt.js/). The thing I like about it is that it allows you to trigger the native select box on whatever OS you are on while still maintaining a consistent styling (http://gregfranko.com/jquery.selectBoxIt.js/#TriggertheNativeSelectBox). Oh how I wish Bootstrap provided this option!

    The only downside to this is that it adds another layer of complexity into a solution, and additional work to ensure compatibility with all other plug-ins as they get upgraded/patched over time. I'm also not sure about Bootstrap 3 compatibility. But, this may be a good solution to ensure a consistent look across browsers and OS's.

    0 讨论(0)
  • 2021-01-30 01:15

    This is easy. You just need to put inside .form-control this:

    .form-control{
            -webkit-appearance:none;
            -moz-appearance: none;
            -ms-appearance: none;
            -o-appearance: none;
            appearance: none;
    }
    

    This will remove browser's appearance and allow your CSS.

    0 讨论(0)
  • 提交回复
    热议问题