Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input group - two inputs close to each other

How can I make input group involves two inputs?

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

This doesn't work, they are horizontal instead of inline

like image 301
UnknownError1337 Avatar asked Sep 23 '13 07:09

UnknownError1337


People also ask

How do I align two input fields side by side in HTML?

try setting specific width to your text-boxes with display: inline-block property. Glad it worked. Then can you please accept my answer. Hello again, it works fine on desktop but on mobile it'a aligned weirdly when placed in the footer.

How do you put a space between two inputs?

The break tag is meant for single line breaks, and not more than one in a row. If you want to add extra whitespace between pieces of text, use CSS padding and margins instead for cleaner code. Or, you can use an HTML <p> tag, as we'll see next.

What is input group append?

input-group class is a container to enhance an input by adding an icon, text or a button in front or behind the input field as a "help text". Use . input-group-prepend to add the help text in front of the input, and . input-group-append to add it behind the input.


2 Answers

working workaround:

<div class="input-group">     <input type="text" class="form-control input-sm" value="test1" />     <span class="input-group-btn" style="width:0px;"></span>     <input type="text" class="form-control input-sm" value="test2" /> </div> 

downside: no border-collapse between the two text-fields, but they keep next to each other

http://jsfiddle.net/EfC26/

Update

thanks to Stalinko

This technique allows to glue more than 2 inputs. Border-collapsing is achieved using "margin-left: -1px" (-2px for the 3rd input and so on)

<div class="input-group">   <input type="text" class="form-control input-sm" value="test1" />   <span class="input-group-btn" style="width:0px;"></span>   <input type="text" class="form-control input-sm" value="test2" style="margin-left:-1px" />   <span class="input-group-btn" style="width:0px;"></span>   <input type="text" class="form-control input-sm" value="test2" style="margin-left:-2px" /> </div> 

http://jsfiddle.net/yLvk5mn1/1/

like image 61
devnull Avatar answered Sep 24 '22 12:09

devnull


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/

like image 37
Anson Kao Avatar answered Sep 22 '22 12:09

Anson Kao