自定义选择下拉箭头不起作用

时间:2018-08-29 00:01:24

标签: html forms css3 select bootstrap-4

我尝试自定义选择下拉列表。但是选择的箭头不起作用。我想把它做成这张图片。但这是我可以达到的程度。这是我想要的样子。请看看。

example dropdown

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

1 个答案:

答案 0 :(得分:0)

修改您的.selectdiv:像这样的CSS之后,用您想要的任何图像更改网址:

.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;

}

相关问题