Reputation: 2119
my select2 is working perfectly, I just have 1 small bug, the arrow down icon from the select box is not showing, do you know guys why?
this make the user a bit confuse I tried find the bug, but I could not fix the error, can you please guys help me? the code is not working here but it is working in the jsfiddle link.
jsfiddle: http://jsfiddle.net/yszv1ob2/
$("#e1").select2();
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css">
<select multiple id="e1" style="width:300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
Upvotes: 25
Views: 31114
Reputation: 1
You could add this css code and it will apply to select span
.select2-selection__arrow {
height: 26px;
position: absolute;
top: 10px;
right: 7px;
width: 20px;
}
.select2-selection__arrow b{
border-color: #009688 transparent transparent transparent;
border-style: solid;
border-width: 5px 4px 0 4px;
height: 0;
left: 50%;
margin-left: -4px;
margin-top: -2px;
position: absolute;
top: 50%;
width: 0;
}
Upvotes: 0
Reputation: 614
Based on Adam Love's answer, this code uses the FontAwesome chevron down icon (although you could easily swap it for a different icon):
.select2-container--default .select2-selection--multiple {
padding-right: 20px;
}
.select2-container--default .select2-selection--multiple::after {
position: absolute;
right: 5px;
top: 42%;
font-family: 'Font Awesome 5 Free';
font-weight: 900;
-webkit-font-smoothing: antialiased;
display: inline-block;
font-style: normal;
font-variant: normal;
text-rendering: auto;
line-height: 1;
content: "\f078";
font-size: 0.7rem;
}
Upvotes: 2
Reputation: 18937
$(function () {
$("#select1").select2();
});
.select2-container--default .select2-selection--multiple:before {
content: ' ';
display: block;
position: absolute;
border-color: #888 transparent transparent transparent;
border-style: solid;
border-width: 5px 4px 0 4px;
height: 0;
right: 6px;
margin-left: -4px;
margin-top: -2px;top: 50%;
width: 0;cursor: pointer
}
.select2-container--open .select2-selection--multiple:before {
content: ' ';
display: block;
position: absolute;
border-color: transparent transparent #888 transparent;
border-width: 0 4px 5px 4px;
height: 0;
right: 6px;
margin-left: -4px;
margin-top: -2px;top: 50%;
width: 0;cursor: pointer
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<select multiple id="select1" style="width: 300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
Source: https://github.com/select2/select2/issues/167#issuecomment-322461384
Upvotes: 7
Reputation: 656
For Select2 version 4.0.5+, this code exactly duplicates the single-select arrow.
.select2-selection--multiple:before {
content: "";
position: absolute;
right: 7px;
top: 42%;
border-top: 5px solid #888;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
}
Upvotes: 41
Reputation: 561
You have used multi-select dropdown and used plugin(Select2) don't add dropdown arrow in multi-select dropdown. So if you want to add dropdown arrow, you have to add some custom CSS like below.
ul.select2-choices {
padding-right: 30px !important;
}
ul.select2-choices:after {
content: "";
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
border-top: 5px solid #333;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
}
Upvotes: 27
Reputation: 11
$("#e1").select2();
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css">
<select multiple id="e1" style="width:300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
Upvotes: 1