Two columns on same row with bootstrap 3.2 - html

I'm trying to place two columns on the same row with Bootstrap 3.2, but am not having any success.
The format that I want is something like this:
BeginDate: txbox1 EndDate: txtbox2
My code is as follows, but I know it's incorrect.
I would appreciate it very much for someone more experienced in Bootstrap for a solution.
<label for="dteBeginDate" class="col-md-2 control-label">Begin Date:</label>
<div class="col-md-10">
<input type="date" id="dteBeginDate">
</div>
<label for="dteEndDate" class="col-md-2 control-label">End Date:</label>
<div class="col-md-10">
<input type="date" id="dteEndDate">
</div>

Bootstrap 3 has a 12 unit width column grid, so this means that each row can have up to 12 columns, and additional columns will be stacked below as another rows. You are setting 24 units (col-md-2 + col-md-10 + col-md-2 + col-md-10), so the second pair of columns are moving to another row (remember that the number post-fix in the class names indicates the column length). Reduce the units to 12, placing them within a "row" class div for completeness (it doesn't constraint that all the elements will be within a single row, though). For example:
<div class="row">
<label for="dteBeginDate" class="col-md-2 control-label">Begin Date:</label>
<div class="col-md-4">
<input type="date" id="dteBeginDate">
</div>
<label for="dteEndDate" class="col-md-2 control-label">End Date:</label>
<div class="col-md-4">
<input type="date" id="dteEndDate">
</div>
</div>

Demo: http://jsbin.com/yukut/1/edit
I think what you are looking for is the form-inline. Look at the docs: http://getbootstrap.com/css/#forms
<form class="form-inline" role="form">
<div class="form-group">
<label for="begin_date">Begin Date:</label>
<input type="date" class="form-control" id="begin_date" placeholder="Start Date">
</div>
<div class="form-group">
<label for="end_date">End Date:</label>
<input type="date" class="form-control" id="end_date" placeholder="End Date">
</div>
</form>

I will make two changes to help you out. The first being to place the label inside the div otherwise you are actually making 4 columns (label, input, label, input). The second being that bootstraps gridsystem is broken into 12 columns per 1 row and your original code used 24 columns (2 label, 10 input, 2 label, 10 input). Check out the bootply here
Code
<div class="container">
<div class="row">
<div class="col-md-6">
<label>Begin Date:</label>
<input type="date" id="dteBeginDate">
</div>
<div class="col-md-6">
<label>End Date:</label>
<input type="date" id="dteEndDate">
</div>
</div>
</div>

Related

How to able to select and input at the same time in the same line?

I have done the code which able to select only
<div class="form-group">
<label for="editAppointmentContact" class="col-sm-2 control-label">Customer Name</label>
<div class="col-sm-10">
<select class="form-control select2contact" id="editAppointmentContact" ></select>
</div>
</div>
and the other line to input
<div class="form-group">
<label for="editAppointmentContact" class="col-sm-2 control-label">Customer Name</label>
<div class="col-sm-10">
<input class="form-control" id="editAppointmentContact" type="text" >
</div>
</div>
How can I make these two select and input at the same time in the same line?
Like you use bootstrap, you can use form-inline. Look the docs :
https://getbootstrap.com/docs/4.0/components/forms/#inline-forms
Try to adapt this layout to your case.
(And I give you an advice, you shouldn't use 2 times the same id in html for different element, as you did with select and text input)
Hope it will helps,
Best regards !

Bootstrap form alignment issue

Trying to align two form elements side by side to create an hours per week field
e.g
Hours per week (box here) - (box here)
but when I use two col-md-2 with a - between them I get the result of
Hours per week (box here) (box here) -
Anyone have a solution to display the - between the two boxes? I've tried using 3 col-md-1 but the alignment gets all out of whack!
The below code follows Bootstrap form construction. Using .input-group allows you to nest .input-group-addon between to fields with the .form-control class - though you do need to specify a width (hence the .col-xs-9).
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form>
<div class="form-group">
<label class="col-xs-3 control-label" for="HoursPerWeek">Hours Per Week</label>
<div class="col-xs-9">
<div class="input-group">
<input type="text" id="BoxOne" class="form-control">
<span class="input-group-addon">-</span>
<input type="text" id="BoxTwo" class="form-control">
</div>
</div>
</div>
</form>
Solution without the bootstrap grid
<form class="inline">
<div>
<label for="HoursPerWeek">Hours Per Week</label>
<input type="text" id="BoxOne">
<label for="#">-</label>
<input type="text" id="BoxTwo">
</div>
</form>
Solution using the bootstrap grid
<form>
<div class="form-group">
<label class="col-md-3" for="HoursPerWeek">Hours Per Week</label>
<input class="col-md-3" type="text" id="BoxOne">
<label class="col-md-3" for="#">-</label>
<input class="col-md-3" type="text" id="BoxTwo">
</div>
</form>

Preserving Column Order on Inline Form Inputs with RTL CSS in Bootstrap

I have 3 columns in my form for inputting the user's phone:
<div class="col-md-5">
<label class="control-label">Phone</label>
<div class="row">
<div class="col-md-4">
<label for="phone_code" class="sr-only"><fmt:message key="phoneCode"/></label>
<select class="form-control" name="phoneCode" id="phone_code">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<span class="col-md-2 text-center">-</span>
<div class="col-md-6">
<label for="phone_number" class="sr-only">phone number</label>
<input type="tel" class="form-control" name="phoneNumber" id="phone_number" dir="LTR" value="${phoneNumber}">
</div>
</div>
</div>
http://www.bootply.com/jgFqaA4r6o
When I include the bootstrap css for rtl:
https://github.com/morteza/bootstrap-rtl
this flips the order of the columns, which in most cases is the desired result. However, I would like the phone input columns to remain in the same order (unaltered).
Including the pull-left class to the first two columns fixes the problem but causes errors when resizing (specifically, shrinking) the screen.
I have tried using/learning the col--pull-/col--push- classes but I couldn't figure out how to make them work here.
Does anybody have any suggestions?
I am also open to changing the general layout if there are improvements on that as well.
Thank you.
I changed the html and used a small "hack" to solve this.
There is still probably a better solution out there. This is my html:
<div class="col-md-5">
<div class="col-sm-4 col-xs-12 pull-left">
<label for="phone_code" class="control-label">phone code</label>
<input type="text" class="form-control">
</div>
<div class="col-sm-8 col-xs-12">
<label for="phone_number" class="control-label">phone number</label>
<input type="tel" class="form-control">
</div>
</div>
http://www.bootply.com/tIW6xBHVGB
The "hack" is the "col-xs-12" class added to the <div> elements. If not added, the divs don't expand to take up the entire row as they should due to the "pull-left" class.
I'm open to hearing other suggestions.

form in rows with details for labels

I am creating a form which looks like this
How will I get the 3 columns and the rows within ? I tried using class="col-md-4"
then within it I created two divs with float left
<label for="Halves">Halves</label> <label for="Quantity">Quantity:</label><input name="qty" id="qty" type="text" size="10"/>
but still not sure how to get the rates under Halves (as per image)
Are you looking for something like this? Js Fiddle
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label class="control-label col-md-6"> Halves</label>
<label class="control-label"> Quantity</label>
<input name="qty" id="qty" type="text" size="10"/>
<div class="input-group">
<i>$14.5 per LB</i>
</div>
</div>
</div>
</div
The above structure can be expanded to multiple columns/rows.

Bootstrap form-inline controls overlapping

I am building an inline form with Bootstrap 3 and I can't figure out how to keep the inputs from overlapping. I hope you can see from the screenshot that the third input is overlapping the second and the fourth in overlapping it. How can I get them to align next to each other?
Here are the main parts of the html;
<div class="form-inline">
<div class="form-group">
<input class="form-control addon-input" id="units" name="units" placeholder="units" value="30" type="text">
</div>
<div class="form-group">
<input class="string optional form-control addon-input" id="unit_price" name="unit_price" placeholder="unit price" type="text">
</div>
</div>