简体   繁体   English

Bootstrap-右侧带有按钮的下拉列表,但通过表单控件使其宽度为100%

[英]Bootstrap - dropdownlist with button to the right, but form-control makes it 100% width

I'm having an issue with getting my 'Create' button to be right of my dropdownlist. 我在将我的“创建”按钮放在下拉列表的右边时遇到问题。 Because the dropdown has a class form-control it makes the width 100% of the space available and so my button wraps underneath. 因为下拉菜单具有类form-control所以它使宽度变为可用空间的100%,因此我的按钮环绕在下面。 If I remove the class the button sits next to the dropdown. 如果我删除课程,则该按钮位于下拉菜单旁边。

http://jsfiddle.net/2y39drrh/ http://jsfiddle.net/2y39drrh/

Rather than writing a CSS class to override form-control's width, is there a better way? 除了编写CSS类来覆盖表单控件的宽度之外,还有更好的方法吗? The forms.less file does say to use form-control with <select> elements... Forms.less文件确实说要对<select>元素使用form-control ...

<div class="form-group">
  <label class="control-label col-md-1" for="Note_NoteTypeId">Type</label>
  <div class="col-md-11">
    <select class="form-control" data-val="true"> 
      <option value="">Select...</option>
      <option value="3">Option1</option>
      <option value="2">Option2</option>
      <option value="1">Option3</option>
    </select>
    <button class="btn btn-success" id="btnCreate" type="button">Create</button>
  </div>
</div>
<div class="form-group">
  <span class="field-validation-valid text-danger"></span>
</div>  

I guess you want something like this? 我想你想要这样的东西吗?

Example 1 例子1

 <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <div class="input-group"> <select class="form-control" data-val="true"> <option value="">Select...</option> <option value="3">Option1</option> <option value="2">Option2</option> <option value="1">Option3</option> </select> <span class="input-group-btn"> <button class="btn btn-success" id="btnCreate" type="button">Create</button> </span> </div> <div class="form-group"> <span class="field-validation-valid text-danger"></span> </div> 

Example 2 例子2

<div class="form-inline">
<select class="form-control" data-val="true"> 
      <option value="">Select...</option>
      <option value="3">Option1</option>
      <option value="2">Option2</option>
      <option value="1">Option3</option>
    </select>
<input type="button" class="btn btn-success" value="Create">
</div>

I'm not sure why, the code I'm inserting to this post works weird on JSFiddle and SO editor. 我不确定为什么,我要插入此代码的代码在JSFiddle和SO编辑器上工作起来很奇怪。 But it works fine on codepen.io 但是在codepen.io上工作正常

 body { max-width: 800px; margin: 0 auto; padding: 2em; } 
 <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="col-md-6"> <select id="vehicle" name="vehicle" class="form-control" data-dropupauto="false"> <option value=""> 1 </option> <option value=""> 2 </option> <option value=""> 3 </option> </select> </div> <div class="col-md-6"> <button class="btn btn-success" id="btnCreate" type="button">Create</button> </div> </div> 

See the example in full page. 请参见整页示例。 I believe that's the reason why SO editor and JSFiddle shows different results. 我相信这就是SO编辑器和JSFiddle显示不同结果的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Bootstrap 3中通过尾随的辅助按钮将最大宽度应用于输入字段form-control? - How do I apply a max-width to an input field form-control with a trailing secondary button in Bootstrap 3? 输入表单控件宽度的引导文档类型无法正确显示 - bootstrap doctype with input form-control width is not show correctly Bootstrap 5 - 将浮动标签定位在表单控件内,宽度为:自动? - Bootstrap 5 - Position floating label inside form-control with width: auto? Bootstrap 3表单控件不堆叠 - Bootstrap 3 form-control not stacking Bootstrap-表单控件输入的同一行中的按钮 - Bootstrap - Button in the same line of input of form-control 如何使 facebook 登录按钮使用引导程序表单控件? - How to make facebook login button use the bootstrap form-control? 如何在 asp:DropDownList 上获取引导下拉列表样式而不使用表单控制类 - How to get bootstrap dropdown list style on asp:DropDownList without using form-control class 如何修复表单控件的宽度? - how to fix the form-control width? Bootstrap .form-control和RecurlyJS iframe - Bootstrap .form-control and RecurlyJS iframe Center Bootstrap表单控件到浏览器的中心 - Center Bootstrap form-control to center of browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM