CSS 更改插入符号图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31294507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:20:58  来源:igfitidea点击:

Change caret icon

csstwitter-bootstrap

提问by brunodd

I am using selectpicker plugin and am trying to change the down arrow icon. I tried using css but it didn't work. How I could change that icon?

我正在使用 selectpicker 插件并试图更改向下箭头图标。我尝试使用 css 但它没有用。我怎么能改变那个图标?

jsfiddle

提琴手

<select class="form-control selectpicker" data-hide-disabled="true" data-show-subtext="true" data-live-search="true">
    <option value="" disabled selected></option>
    <option value="update" data-subtext="old subtext">Update subtext</option>
    <option value="delete" data-subtext="more subtext">Delete subtext</option>
</select>

CSS

CSS

.bootstrap-select.btn-group .dropdown-toggle .caret {
    display: none;
}

回答by DavidG

It depends on what you want to change it to, but currently the caret comes from this CSS which gives it zero size but applies a border to mimic the down arrow:

这取决于你想把它改成什么,但目前插入符号来自这个 CSS,它给它零大小,但应用边框来模仿向下箭头:

.caret {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 2px;
  vertical-align: middle;
  border-top: 4px dashed;
  border-top: 4px solid;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
}

You could change it to a green square for example:

您可以将其更改为绿色方块,例如:

.bootstrap-select.btn-group .dropdown-toggle .caret {
  width: 10px;
  height: 10px;
  border: none;
  background-color: green;
}

Demonstration fiddle: http://jsfiddle.net/pvT8Q/460/

演示小提琴:http: //jsfiddle.net/pvT8Q/460/

Or you could use the Bootstrap Glyphicons:

或者你可以使用 Bootstrap Glyphicons:

.bootstrap-select.btn-group .dropdown-toggle .caret {
  width: 10px;
  height: 10px;
  border: none;
  font-family: 'Glyphicons Halflings';
}

.bootstrap-select.btn-group .dropdown-toggle .caret:before {
  content: "\e003";
}

Demonstration fiddle: http://jsfiddle.net/pvT8Q/461/(I leave the positioning up to you)

演示小提琴:http: //jsfiddle.net/pvT8Q/461/(我把定位留给你)

回答by Razib Hossain

js fiddle example here here

js 小提琴示例在这里

//select box arrow icon with pure css
.select-toggle{
   position: relative;
   display: inline-block;
   background:white;
   border:1px solid red;
}

.select-toggle::after{
  position: absolute;
  top: 10px;
  right: 5px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #023F55;
  content: "";
  pointer-events: none;
}

.select-toggle select{
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
<div class="select-toggle">
  <select>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </select>
</div>

回答by Vivek Singh

Here is the fiddle link you can use to change the dropdown caret icon : https://jsfiddle.net/vivek1313/0xugbrat/

这是您可以用来更改下拉插入符号图标的小提琴链接:https: //jsfiddle.net/vivek1313/0xugbrat/

<div class="selection-wrapper" onclick="toggleUpDown()">

<select name="list" id="languageDropdown" class='selection'>
  <option value="apple">Apple</option>
  <option value="orange">Orange</option>
  <option value="banana">Banana</option>
  <option value="Mango">Mango</option>
</select>
<div id="caret" class="triangle triangle-up"></div>
</div>
<script>
var triangleEl = document.getElementById('caret');
var languageDropdown = document.getElementById('languageDropdown');
function toggleUpDown() {

    if(!triangleEl.classList.contains('triangle-up')){
    showDownArrow();
  } else {
     showUpArrow();
  }

} 


 function showUpArrow() {
   triangleEl.classList.remove('triangle-up');
    triangleEl.classList.add('triangle-down')
 }

function showDownArrow() {
    triangleEl.classList.remove('triangle-down');
      triangleEl.classList.add('triangle-up')
}
languageDropdown.addEventListener('blur',toggleUpDown)
</script>

.selection-wrapper {
  position: relative;
  width: 30%;
}
.selection {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding:5px;
  position: relative;
  content:'';
}

.triangle{
  position: absolute;
  top: 30%;
  right: 5px; 
  width: 0;
  height: 0;
  content: "";
  pointer-events: none;
  z-index:5;
}

.triangle-up {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #023F55;

}

.triangle-down {
  top: 10%;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid transparent;
  border-bottom: 6px solid  #023F55;
}