There would seem to be no way to do this using css styles and/or classes in the markup but if you are open to javascript -- in the example below, jQuery -- then you can hook the selectpicker's show.bs.select
event and modify the widget as follows:
$('.selectpicker').on('show.bs.select', function () {
var $dropdownMenu = $(this).nextAll('div.dropdown-menu').first();
if ($dropdownMenu.length > 0) {
$dropdownMenu.css('min-width', '').css('max-width', '100%');
var $inner = $dropdownMenu.find('div.inner');
if ($inner.length > 0) {
$inner.css('overflow-x', 'hidden');
}
}
});
Here I am accessing the div for the dropdown menu that it uses and removing whatever it is assigning for the min-width
and then setting max-width
to 100% and then to remove the horizontal scrollbar that might be shown if options are too wide I am setting the dropdown's 'inner' div overflow-x
to hidden
.
The result is a dropdown menu that is constrained to the width of the button that shows it with any options that have text that is too wide being truncated.
More work than I wanted to do on this but the default behavior makes dropdowns unusable on small-screen displays...