I am trying to display a year range input on a form that has a 2 textboxes. One for the min and one for the max and are separated by a dash.
I want this all on the same line using bootstrap, but I cannot seem to get it to work correctly.
Here's my code:
<form id="Form1" class="form-horizontal" role="form" runat="server"> <div class="row"> <div class="form-group"> <label for="tbxContactPhone" class="col-sm-2 control-label">Year</label> <div class="col-sm-4"> <asp:TextBox ID="TextBox1" CssClass="form-control" runat="server" MaxLength="4" /> </div> <label class="col-sm-2 control-label">-</label> <div class="col-sm-4"> <asp:TextBox ID="TextBox2" CssClass="form-control" runat="server" MaxLength="4" /> </div> </div> </div> </form>
Here's what it looks like now:
The technique to create two forms horizontally is simple. You simply code two <div class=”span6″> columns and insert the required form markup. Do not add the . well class to the span columns or else it breaks up everything.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
Form Grids You can add columns and rows by adding <div class="row"> and <div class="col"> to your form. In the example above, the email and password fields are separated into two columns within a row. This is why they are displayed side by side on a webpage.
How about using an input group to style it on the same line?
Here's the final HTML to use:
<div class="input-group"> <input type="text" class="form-control" placeholder="Start"/> <span class="input-group-addon">-</span> <input type="text" class="form-control" placeholder="End"/> </div>
Which will look like this:
Here's a Stack Snippet Demo:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet"/> <div class="input-group"> <input type="text" class="form-control" placeholder="Start"/> <span class="input-group-addon">-</span> <input type="text" class="form-control" placeholder="End"/> </div>
I'll leave it as an exercise to the reader to translate it into an asp:textbox
element
@KyleMit's answer on Bootstrap 4 has changed a little
<div class="input-group"> <input type="text" class="form-control"> <div class="input-group-prepend"> <span class="input-group-text">-</span> </div> <input type="text" class="form-control"> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With