How do I change the width of a select field, when using Twitter bootstrap? Adding input-xxlarge
CSS classes doesn't seem to work (like it does on other form elements), so the elements in my drop down are currently cut off.
This question is related to
css
twitter-bootstrap
twitter-bootstrap-2
For me Pawan's css class combined with display: inline-block (so the selects don't stack) works best. And I wrap it in a media-query, so it stays Mobile Friendly:
@media (min-width: $screen-xs) {
.selectwidthauto {
width:auto !important;
display: inline-block;
}
}
In bootstrap 3, it is recommended that you size inputs by wrapping them in col-**-#
div tags. It seems that most things have 100% width, especially .form-control
elements.
I did a workaround by creating a new css class in my custom stylesheet as follows:
.selectwidthauto
{
width:auto !important;
}
And then applied this class to all my select elements either manually like:
<select id="State" class="selectwidthauto">
...
</select>
Or using jQuery:
$('select').addClass('selectwidthauto');
with bootstrap use class input-md = medium, input-lg = large, for more info see https://getbootstrap.com/docs/3.3/css/#forms-control-sizes
Tested alone, <select class=input-xxlarge>
sets the content width of the element to 530px. (The total width of the element is slightly smaller than that of <input class=input-xxlarge>
due to different padding. If this a a problem, set the paddings in your own style sheet as desired.)
So if it does not work, the effect is prevented by some setting in your own style sheet or maybe in the use other settings for the element.
You can use something like this
<div class="row">
<div class="col-xs-2">
<select id="info_type" class="form-control">
<option>College</option>
<option>Exam</option>
</select>
</div>
</div>
Source: Stackoverflow.com