Reputation: 1187
I am using jQuery
chosen for my multi-select
box. However, I do find the styles pre-defined in chosen.css
file is kind of hard to overwrite, which totally getting rid of chosen.css
might also not be a very good option.
Here is my fiddle: https://jsfiddle.net/k1Lr0342/
HTML:
<select class="chosen" multiple="true" style="height: 34px; width: 280px">
<option>Choose...</option>
<option>jQuery</option>
<option selected="selected">MooTools</option>
<option>Prototype</option>
<option selected="selected">Dojo Toolkit</option>
</select>
css:
.chosen-choices {
border-radius: 3px;
box-shadow: inset 0px 1px 2px rgba(0,0,0,0.3);
border: none;
height: 34px !important;
cursor: text;
margin-top: 12px;
padding-left: 15px;
border-bottom: 1px solid #ddd;
width: 285px;
text-indent: 0;
margin-left: 30px;
}
I tried to directly write the css for .chosen-choices
ul
. Some works like border-radius
and box-shadow
. But others: margin, height, padding, border
, etc. get overwritten by chosen.css
file. One option is to put !important
for every setting which doesn't work. This will work for most stuffs but still not the height. Any thoughts?
Upvotes: 13
Views: 36330
Reputation: 750
For those who are interested this is some sass I worked out that will style the chosen select box, the biggest issue is it uses background as opposed to background-colour which is why it ignores your css colours`.chosen-drop border-bottom-left-radius: 10px border-bottom-right-radius: 10px
&.chosen-results li.result-selected display: none !important
.chosen-select option display: none
.chosen-container width: 100% !important
.chosen-choices padding: 5px !important background: $inputBackground !important
li.search-choice color: $text !important background: $alternateBackground !important border-radius: 10px !important
span
padding: 10px`
Upvotes: 0
Reputation: 16373
I had to use:
$(".chzn-results li").css("width", "100%");
not sure if it's because I have a really old version or what.
Upvotes: 0
Reputation: 1005
Little late but I thought I'd answer since I ran into this. Since the chosen items you see are based on the select menu it hides, you have to find the element in the div immediately following it (created by chosen) and style it. You can do this with Jquery assuming you know it's value.
$('.your-select-menu').next().find('.search-choice').each(function() {
if ($(this).text() === someValue) {
$(this).css("border-color", "#00b300");
}
})
Upvotes: 0
Reputation: 918
Try using jQuery, here is the working JSFIDDLE
$(".chosen-choices li").css("background","red");
Upvotes: 2
Reputation: 1360
CSS will accept style that uses more specified selector.
.chosen-container-multi .chosen-choices {
/*blah blah*/
}
.chosen-choices {
/* less specificity, this style might not work */
}
Upvotes: 10
Reputation: 774
If you look at .chosen-choices
in chosen.css, you will find the height is auto!important
. Delete (or comment) those !important
and that should be fine.
You can use your browser's element inspector to check the applied css. I personally use Chrome developer tools every time. Save me alot of hassle
Upvotes: -1