【问题标题】:How to make <select> element with my own arrow down icon?如何使用我自己的向下箭头图标制作 <select> 元素?
【发布时间】:2017-10-03 12:44:12
【问题描述】:

我想在所有浏览器的选择元素右侧都有我自己的箭头图标。我试图使用伪元素:after,但它不起作用。

select {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  &:after {
    content: 'f175';
    font-size: 12px;
    position: absolute;
    z-index: 999;
    top: 0px;
    right: 13px;
  }
}
<select name="" size="1">
    <option value="wybierz z listy">wybierz z listy</option>
    <option value="Normal">Normal</option>
    <option value="High">High</option>
    <option value="Emergency">Emergency</option>
</select>

【问题讨论】:

    标签: html css select css-selectors


    【解决方案1】:

    你可以使用下面的图片

    select {
      position: relative;
      appearance: none;
      -webkit-appearance: none;
      -moz-appearance: none;
      padding: 5px;
      width: 120px;
      background: transparent url("http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png") no-repeat right center;
    }
    <select name="" size="1">
      <option value="wybierz z listy">wybierz z listy</option>
      <option value="Normal">Normal</option>
      <option value="High">High</option>
      <option value="Emergency">Emergency</option>
    </select>

    【讨论】:

      【解决方案2】:

      试试这个:

      select {
        -webkit-appearance: none;
        -moz-appearance: none;
        background: transparent;
        background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
        background-repeat: no-repeat;
        background-position-x: 100%;
        background-position-y: 5px;
        border: 1px solid #dfdfdf;
        border-radius: 2px;
        margin-right: 2rem;
        padding: 1rem;
        padding-right: 2rem;
      }
      <select name="" size="1">
        <option value="wybierz z listy">wybierz z listy</option>
        <option value="Normal">Normal</option>
        <option value="High">High</option>
        <option value="Emergency">Emergency</option>
      </select>

      【讨论】:

        【解决方案3】:

        只需从您的 css 中删除以下样式,它就会起作用

        -webkit-appearance: none;
        -moz-appearance: none;
        

        【讨论】:

          猜你喜欢
          • 2010-10-02
          • 2012-06-07
          • 2020-07-06
          • 1970-01-01
          • 1970-01-01
          • 2011-11-08
          • 1970-01-01
          • 2021-11-21
          • 2013-10-22
          相关资源
          最近更新 更多