【问题标题】:Customized select drop down arrow not working自定义选择下拉箭头不起作用
【发布时间】:2019-02-03 16:01:08
【问题描述】:

我尝试自定义选择下拉菜单。但是选择的箭头不起作用。我想把它做成这个图像。但这是我能达到的程度。这是我想要的图像。请看一下。

HTML

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="selectdiv ">
  <label>
      <select>
          <option selected> Select Box </option>
          <option>Option 1</option>
          <option>Option 2</option>
          <option>Last long option</option>
      </select>
  </label>
</div>

CSS

   body {
  background: #f2f2f2;
}

.selectdiv {
  position: relative;
  /*Don't really need this just for demo styling*/

  float: left;
  min-width: 150px;
  margin: 50px 33%;
  background:rgba(43, 43, 43, 0.4);
  border-radius: 5px 0 0 5px;
  padding: 5px;
}

.selectdiv:after {
    content: '\f078';
    font: normal normal normal 17px/1 FontAwesome;
    color: #2B2B2B;
    right: -44px;
    top: 0px;
    height: 33px;
    padding: 15px 12px 0px 12px;
    border:1px solid #2B2B2B;
    border-radius: 0 5px 5px 0;
    position: absolute;
}

/* IE11 hide native button (thanks Matt!) */
select::-ms-expand {
display: none;
}

.selectdiv select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* Add some styling */ 
  display: block;
  width: 100%; 
  max-width: 150px;
  margin: 5px 0px 5px 0px;
  padding: 0px 24px;
  font-size: 16px;
  line-height: 1.75;
  color: #333;
  background: transparent;
  -ms-word-break: normal;
  word-break: normal;
  border: 0;
  border-bottom: 1px solid #fff;
  outline:none;
}

我在此处添加了 codepen.io 链接。请看一下。 https://codepen.io/anon/pen/vzKrXK

【问题讨论】:

    标签: html forms css select bootstrap-4


    【解决方案1】:

    修改你的.selectdiv:像这样在css之后,用你想要的任何图像更改url:

    .selectdiv:after {
     content: '';
     background-color: #fff;
     background: url(http://icocentre.com/Icons/g-arrow-down.png?size=16) no- repeat right #ddd;
     -webkit-appearance: none;
     background-position-x: 5px;  
     width: 10px;
     font: normal normal normal 17px/1 FontAwesome;
     color: #0ebeff;
     right: 11px;
     top: 6px;
     height: 34px;
     padding: 15px 0px 0px 8px;
     border-left: 1px solid #0ebeff;
     position: absolute;
     pointer-events: none;
    

    }

    【讨论】:

    • 它只是与我的 div 重叠。!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多