Input group - two inputs close to each other

后端 未结 11 996
刺人心
刺人心 2020-12-12 17:47

How can I make input group involves two inputs?

相关标签:
11条回答
  • 2020-12-12 18:20

    I have searched for this a few minutes and i couldn't find any working code.

    But now i finaly did it ! Take a look:

    <div class="input-group" id="unified-inputs">
    <input type="text" class="form-control" placeholder="MinVal" />
    <input type="text" class="form-control" placeholder="MaxVal" />
    </div>
    

    And css

    #unified-inputs.input-group { width: 100%; }
    #unified-inputs.input-group input { width: 50% !important; }
    #unified-inputs.input-group input:last-of-type { border-left: 0; }
    

    http://jsfiddle.net/4Ln8d7zq/)

    0 讨论(0)
  • 2020-12-12 18:21

    It almost never makes intuitive sense to have two inputs next to each other without labels. Here is a solution with labels mixed in, which also works quite well with just a minor modification to existing Bootstrap styles.

    Preview: enter image description here

    HTML:

    <div class="input-group">
      <span class="input-group-addon">Between</span>
      <input type="text" class="form-control" placeholder="Type something..." />
      <span class="input-group-addon" style="border-left: 0; border-right: 0;">and</span>
      <input type="text" class="form-control" placeholder="Type something..." />
    </div>
    

    CSS:

    .input-group-addon {
      border-left-width: 0;
      border-right-width: 0;
    }
    .input-group-addon:first-child {
      border-left-width: 1px;
    }
    .input-group-addon:last-child {
      border-right-width: 1px;
    }
    

    JSFiddle: http://jsfiddle.net/yLvk5mn1/31/

    0 讨论(0)
  • 2020-12-12 18:22

    With Bootstrap 4.1 I found a width solution by percentage:

    The following shows an input-group with 4 Elements: 1 text an 3 selects - working well:

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    
    <div class="input-group input-group-sm">
    	<div class="input-group-prepend">
    		<div class="input-group-text">TEXT:</div>
    	</div>
    	<select name="name1" id="name1" size="1" style="width:4%;" class="form-control">
    		<option value="">option</option>
    		<!-- snip -->
    	</select>				
    	<select name="name2" id="name2" size="1" style="width:60%;" class="form-control">
    		<option value="">option</option>
    		<!-- snip -->
    	</select>					
    	<select name="name3" id="name3" size="1" style="width:25%;" class="form-control">
    		<option value="">option</option>
    		<!-- snip -->
    	</select>
    </div>

    0 讨论(0)
  • 2020-12-12 18:23

    If you want to include a "Title" field within it that can be selected with the <select> HTML element, that too is possible

    PREVIEW

    CODE SNIPPET

    <div class="form-group">
      <div class="input-group input-group-lg">
        <div class="input-group-addon">
          <select>
            <option>Mr.</option>
            <option>Mrs.</option>
            <option>Dr</option>
          </select>
        </div>
        <div class="input-group-addon">
          <span class="fa fa-user"></span>
        </div>
        <input type="text" class="form-control" placeholder="Name...">
      </div>
    </div>
    
    0 讨论(0)
  • 2020-12-12 18:29

    Create a input-group-glue class with this:

    .input-group-glue {
      width: 0;
      display: table-cell;
    }
    
    .input-group-glue + .form-control {
      border-left: none;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="input-group">
      <input type="text" class="form-control" value="test1" />
      <span class="input-group-glue"></span>
      <input type="text" class="form-control" value="test2" />
      <span class="input-group-glue"></span>
      <input type="text" class="form-control" value="test2" />
    </div>

    0 讨论(0)
  • 2020-12-12 18:34

    Assuming you want them next to each other:

    <form action="" class="form-inline">
        <div class="form-group">
            <input type="text" class="form-control" placeholder="MinVal">
        </div>
        <div class="form-group">    
             <input type="text" class="form-control" placeholder="MaxVal">   
        </div>
    </form>
    

    JSFiddle

    Update Nr.1: Should you want to use .input-group with this example:

    <form action="" class="form-inline">
        <div class="form-group">
            <div class="input-group">
              <span class="input-group-addon">@</span>
              <input type="text" class="form-control" placeholder="Username">
            </div>
        </div>
        <div class="form-group">    
            <div class="input-group">
              <input type="text" class="form-control">
              <span class="input-group-addon">.00</span>
            </div>
        </div>
    </form>
    

    JSFiddle

    The class .input-group is there to extend inputs with buttons and such (directly attached). Checkboxes or radio buttons are possible as well. I don't think it works with two input fields though.

    Update Nr. 2: With .form-horizontal the .form-group tag basically becomes a .row tag so you can use the column classes such as .col-sm-8:

    <form action="" class="form-horizontal">
        <div class="form-group">
            <div class="col-sm-8">
                <input type="text" class="form-control" placeholder="MinVal">
            </div>
            <div class="col-sm-4">
                <input type="text" class="form-control" placeholder="MaxVal">
            </div>
        </div>
    </form>
    

    Updated JSFiddle with all three examples

    0 讨论(0)
提交回复
热议问题