twitter-bootstrap 在 Bootstrap 3 的同一行上保留按钮和带有选择下拉列表的表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20342268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:22:43  来源:igfitidea点击:

Keep buttons and form with select dropdown on same row in Bootstrap 3

formstwitter-bootstraptwitter-bootstrap-3

提问by bhall

I'm struggling to keep buttons, and a form with a <select>tag (including its label) all on the same row in Bootstrap 3. Whenever the form is rendered, it seems to add a line break before the form. Here's what I have put together so far (http://www.bootply.com/98022):

我正在努力将按钮和带有<select>标签(包括其标签)的表单都保留在 Bootstrap 3 的同一行上。每当呈现表单时,它似乎都会在表单之前添加一个换行符。到目前为止,这是我汇总的内容(http://www.bootply.com/98022):

<div class="container">
    <div class="row">
      <button class="btn btn-default">Test 1</button>
      <button class="btn btn-default">Test 2</button>
      <form role="form" class="form-inline">      
      <div class="form-group">
        <label for="selectUser">Select:</label>
        <select id="selectUser" class="form-control selectWidth">
          <option class="">One</option>
          <option class="">Two</option>
          <option class="">Three</option>
        </select>
      </div>
      <div class="btn-group">
        <button class="btn btn-default">Test 3</button>
      </div>
      </form>
    </div> <!-- End Row -->
</div> <!-- End Container -->

I thought that the class="form-inline"would keep it on the same row. Unfortunately, this is how it renders:

我认为它class="form-inline"会保持在同一行。不幸的是,它是这样呈现的:

The form is rendering on a separate line instead of staying on the same line/row

表单呈现在单独的行上,而不是停留在同一行/行上

This is a mock-up I created in an image editing program of what I'd like it to look like:

这是我在图像编辑程序中创建的模型,我希望它看起来像:

This is a mock-up of how I'd like the buttons to display

这是我希望按钮如何显示的模型

I have deliberately chosen to use the <select>element instead of Bootstrap dropdowns, as the interface on mobile devices is optimal (the list will be quite large and trying to select the correct option on a small screen is easier with a form <select>element).

我特意选择使用该<select>元素而不是 Bootstrap 下拉菜单,因为移动设备上的界面是最佳的(列表将非常大,并且使用表单<select>元素更容易在小屏幕上选择正确的选项)。

I found similar questions, but most either don't address the <select>tag within a form, or are for older versions of Bootstrap (2.x). Any help would be greatly appreciated.

我发现了类似的问题,但大多数问题要么没有解决<select>表单中的标签,要么是针对旧版本的 Bootstrap (2.x)。任何帮助将不胜感激。

Thanks!

谢谢!

回答by Bass Jobsen

Your first two button are not inside the formtag.

您的前两个按钮不在form标签内。

It seems form-inlinedoes not define styles for labels, so add a left float some padding and set the width of the select to auto.

似乎form-inline没有定义标签的样式,所以添加一个左浮动一些填充并将选择的宽度设置为自动。

<div class="container">
    <div class="row">
    <form role="form" class="form-inline">  
      <button class="btn btn-default">Test 1</button>
      <button class="btn btn-default">Test 2</button>
      <div class="form-group">
        <label for="selectUser" style="float:left;padding: 6px 12px 2px 12px;">Select:</label>
        <select id="selectUser" style="width:auto;" class="form-control selectWidth">
          <option class="">One</option>
          <option class="">Two</option>
          <option class="">Three</option>
        </select>
      </div>
      <div class="btn-group">
        <button class="btn btn-default">Test 3</button>
      </div>
      </form>
    </div> <!-- End Row -->
</div> <!-- End Container -->