调整窗口大小时Bootstrap <select>宽度,内容太宽

Vik*_*ren 5 html css twitter-bootstrap

如何使下拉大小适合内容(在我的情况下,它发生在缩小浏览器到小于某个特定大小,然后内容开始消失?我最好不要任何自定义CSS,任何内置到bootstrap到支持这个?

 <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form class="form-horizontal" role="form" enctype="multipart/form-data" id="inputForm" name="inputForm" novalidate>
<div class="well">
<div class="form-group">
    <label class="col-xs-3 control-label"><strong>4.</strong>&nbsp;Select thing</label>
    <div class="col-xs-2">
        <select class="form-control">
            <option>Short
            </option>
            <option>Medium lenght
            </option>
            <option>Much much much longer text not fitting when resizing
            </option>
        </select>
    </div>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)

xan*_*key 17

老问题,新答案。您可以w-auto在引导程序 4中将类设置为。


Ted*_*Ted 15

选项1:您可以添加width:auto到选择中,尽管它总是会调整大小以适应最长的内容,并忽略您的col类.请参阅代码段:

 <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form class="form-horizontal" role="form" enctype="multipart/form-data" id="inputForm" name="inputForm" novalidate>
<div class="well">
<div class="form-group">
    <label class="col-xs-3 control-label"><strong>4.</strong>&nbsp;Select thing</label>
    <div class="col-xs-2">
        <select class="form-control" style="width:auto;">
            <option>Short
            </option>
            <option>Medium lenght
            </option>
            <option>Much much much longer text not fitting when resizing
            </option>
        </select>
    </div>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)

选项2将使用内联形式,请参阅此bootply以获取功能示例


小智 8

新答案

引导程序 v5

您可以将选择元素放入容器中:

  <div class="container w-25">
    <select class="form-select  h-100 w-100" aria-label="">
      <option>Images</option>
    </select>
  </div>
Run Code Online (Sandbox Code Playgroud)