Bootstrap 3选择输入表单内联 [英] Bootstrap 3 select input form inline

查看:88
本文介绍了Bootstrap 3选择输入表单内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取输入并选择彼此内联的选项,例如此演示使用Bootstrap 2(无效链接) .

I'm trying to get input and select option inline attached with each other like this demo using Bootstrap 2 (dead link).

遵循Bootstrap 3指南,我设法做到这一点:

Following Bootstrap 3 guidelines I manage to do this:

<div class="container">
    <div class="col-sm-7 pull-right well">
      <form class="form-inline" action="#" method="get">
        <div class="form-group col-sm-5">
          <input class="form-control" type="text" value="" placeholder="Search" name="q">
        </div>
        <div class="form-group col-sm-3">
          <select class="form-control" name="category">
              <option>select</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
          </select>
        </div>
        <button class="btn btn-primary col-sm-3 pull-right" type="submit">Search</button>
      </form>
    </div>
</div>

它具有响应能力,但是如果没有一些讨厌的CSS hacks,就无法附加输入和选择.我发现有很多带有附加按钮的示例,但这不适用于select元素.

It's responsive, but input and select can't be attached without some nasty css hacks. I found lot of examples with attached buttons, but that does not work with select element.

推荐答案

我认为我偶然发现了一个解决方案.唯一要做的就是在<input><select>之间插入一个空的<span class="input-group-addon"></span>.

I think I've accidentally found a solution. The only thing to do is inserting an empty <span class="input-group-addon"></span> between the <input> and the <select>.

另外,您可以通过减小其宽度,水平填充和边框来使其不可见":

Additionally you can make it "invisible" by reducing its width, horizontal padding and borders:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<div class="input-group">
    <span class="input-group-addon" title="* Price" id="priceLabel">Price</span>
    <input type="number" id="searchbygenerals_priceFrom" name="searchbygenerals[priceFrom]" required="required" class="form-control" value="0">
    <span class="input-group-addon">-</span>
    <input type="number" id="searchbygenerals_priceTo" name="searchbygenerals[priceTo]" required="required" class="form-control" value="0">
  
    <!-- insert this line -->
    <span class="input-group-addon" style="width:0px; padding-left:0px; padding-right:0px; border:none;"></span>
  
    <select id="searchbygenerals_currency" name="searchbygenerals[currency]" class="form-control">
        <option value="1">HUF</option>
        <option value="2">EUR</option>
    </select>
</div>

在Chrome和FireFox上进行了测试.

Tested on Chrome and FireFox.

这篇关于Bootstrap 3选择输入表单内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆