我正在为我正在使用的搜索UI使用bootstrap-select,一切工作正常,并且库附带了很多不错的选择。我想将默认的下拉图标替换为我的字体可怕图标,这样我就可以控制图标的样式。我尝试了默认的图标更改方式,该方法不起作用,我在这里做错了。
这是我没有运气尝试过的图标更改功能
$('.selectpicker').selectpicker({
iconBase: 'fa',
tickIcon: 'fa-chevron-down',
});
有没有这样做的CSS方法?如果有上述工作功能,那会更好。
到目前为止,这是我的工作
.dnow-searchWizard-wrap .dropdown.bootstrap-select button.btn-light {
background-color: #fff;
padding: 1rem;
}
.dnow-searchWizard-wrap .btn-primary {
padding: 1rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>slick slider</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<link href="https://unpkg.com/ionicons@4.4.8/dist/css/ionicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.2/css/bootstrap-select.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<section class="dnow-searchWizard-wrap bg-light p-5">
<div class="container">
<div class="row text-center">
<div class="col-lg-12 mb-4">
<h2>H2 Find Solutions That Work for You</h2>
</div>
<div class="col-lg-12 mb-4">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit do eiusmod.</p>
</div>
</div>
<div class="row">
<div class="col-lg-2 align-self-center">
<p><strong>I AM LOOKING FOR</strong></p>
</div>
<div class="col-lg-3">
<div class="form-group">
<select class="selectpicker form-control">
<optgroup label="Picnic">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</optgroup>
<optgroup label="Camping">
<option>Tent</option>
<option>Flashlight</option>
<option>Toilet Paper</option>
</optgroup>
</select>
</div>
</div>
<div class="col-lg-1 align-self-center text-center">
<p><strong>IN</strong></p>
</div>
<div class="col-lg-3">
<div class="form-group">
<select class="selectpicker form-control">
<optgroup label="Picnic">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</optgroup>
<optgroup label="Camping">
<option>Tent</option>
<option>Flashlight</option>
<option>Toilet Paper</option>
</optgroup>
</select>
</div>
</div>
<div class="col-lg-3">
<button class="btn btn-primary">Show My Results</button>
</div>
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.2/js/bootstrap-select.min.js"></script>
<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.2/js/i18n/defaults-*.min.js"></script>
<script>
$(document).ready(function () {
$('.selectpicker').selectpicker({
iconBase: 'fa',
tickIcon: 'fa-check',
});
});
</script>
</body>
</html>
答案 0 :(得分:0)
可以使用下面的css对矢量图像进行处理。也可以使用':after'并使用'content'样式来实现,但是我还没有尝试过。如果没有其他人帮助,我至少给了您一个可行的解决方案。
.changedSelect {
padding: 0 32px 0 5px !important;
-webkit-appearance: none;
-moz-appearance: none;
background-color: white;
background-image: url('../DropDownArrow.png');
background-repeat: no-repeat;
background-position: right 5px center;
background-size: 20px 20px;
}
/*Hide the original drop down arrow on internet explorer*/
.changedSelect::-ms-expand {
display: none;
};
更新:所以,作为我这个了不起的人,浏览器不允许您使用:after和content CSS来添加一个很棒的字体图标,就我所知,我发布的解决方案将是添加自定义箭头的唯一方法,除非添加包装器。根据从IvanS添加的注释,可以在之前和之后使用Font Awesome图标添加到普通divs
答案 1 :(得分:0)
bootstrap 4使用边框技巧添加了其下拉图标,因此,在使用dropdown :: after添加我自己的图标之后,我不得不将所有边框都覆盖为无以删除默认图标。您可以对下拉菜单执行相同的操作。
.dropdown-toggle::after {
font-family: "Ionicons";
/* display: inline-block; */
content: '\f123';
/* width: 0;
height: 0;
margin-left: 0.255em;
vertical-align: 0.255em; */
border-top: none;
border-right: none;
border-bottom: none;
border-left: none;
margin-right: 1rem;
}
.dropup .dropdown-toggle::after {
/*display: inline-block;
width: 0;
height: 0;
margin-left: .255em;
vertical-align: .255em;*/
font-family: "Ionicons";
content: "\f126";
border-top: 0;
border-right: 0;
border-bottom: 0;
border-left: 0;
}