bootstrap input forms alignment - html

I am trying to create a data entry form using bootstrap and forms input.
It seems to work well until on some lines it puts one entry on the line instead of 3.
I have tried various routes and always see this behavior.
Any help at understanding why it is doing this wound be greatly appreciated.
I have a plunker example here
<fieldset class="scheduler-border well">
<legend class="scheduler-border">Customer</legend>
<form class="form-group" role="form">
<div class="form-group left">
<label for="input16" class="col-md-2 control-label">Label A</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Label A" placeholder="Label A">
</div>
<label for="input17" class="col-md-2 control-label">Customer Label ALpha Beta</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Customer Label ALpha Beta" placeholder="Customer Label ALpha Beta">
</div>
<label for="input18" class="col-md-2 control-label">Label C</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Label C" placeholder="Label C">
</div>
<label for="input15" class="col-md-2 control-label">Label D</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Label AD" placeholder="Label D">
</div>
</div>
</form>
</fieldset>
If you the launch the preview window and increase the width you should be able to see the behavior.

Not entirely sure if this is what you want, but I guess what you mean is that for some screen sizes Label D ends up on the fourth column while it should be on the first. The problem here is that your label Customer Label Alpha Beta takes up too much height and since bootstrap's column are just a clever usage of float:left, Label D will be to the right of it.
The easiest way to adjust your code is to wrap groups of 3 labels/inputs in a .row to clear the floats once a row is full.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<fieldset class="scheduler-border well">
<legend class="scheduler-border">Customer</legend>
<form class="form-group" role="form">
<div class="form-group left container">
<div class="row">
<label for="input16" class="col-md-2 control-label">Label A</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Label A" placeholder="Label A">
</div>
<label for="input17" class="col-md-2 control-label">Customer Label ALpha Beta</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Customer Label ALpha Beta" placeholder="Customer Label ALpha Beta">
</div>
<label for="input18" class="col-md-2 control-label">Label C</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Label C" placeholder="Label C">
</div>
</div>
<div class="row">
<label for="input15" class="col-md-2 control-label">Label D</label>
<div class="col-md-2">
<input type="number" class="form-control" id="Label AD" placeholder="Label D">
</div>
</div>
</div>
</form>
</fieldset>
Of course this solution isn't prefect, for example your rows might end up with different vertical distances. Maybe getting rid of the -col-* and using the classes .form-inline or `.form-horizontal will work better for you.

Related

Bootstrap 4 - can't horizontally align a vertical form

I have the following form code:
<div id="site" class="container-fluid">
<div class="row">
<div class="my-4 offset-3 col-6 justify-content-center align-items-center">
<form action="/some/path" method="post">
<div class="form-group row">
<label for="username" class="col-2 col-form-label">Username</label>
<div class="col-4">
<input type="text" class="form-control" id="username" name="_username" required="required" autocomplete="username" />
</div>
</div>
<div class="form-group row">
<label for="password" class="col-2 col-form-label">Password</label>
<div class="col-4">
<input type="password" class="form-control" id="password" name="_password" required="required" autocomplete="current-password" />
</div>
</div>
<div class="form-group row">
<div class="col-2"></div>
<div class="col-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me" class="form-check-label">Remember me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-6">
<button class="btn btn-burnt-orange" type="submit" id="_submit" name="_submit">Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
I want the form to be centered on the page, but instead, it's still further to the left than center as shown by this screenshot:
I thought my math was correct: Bootstrap uses a 12-column grid, so by using a 3-column offset, and a 6-column content area, I'd have essentially two 3-column gutters on each side. And by specifying the form rows to add up to 6-columns (2-column labels and 4-column inputs), the form would fill the 6-column content area, thereby automatically centering itself. But I'm obviously wrong.
So, what can I do to actually center this thing? And to make it 6 columns wide (because, judging by the screenshot, it isn't)?
The form is horizontally centered, but it's only half the width of it's parent. The issue is...
"And by specifying the form rows to add up to 6-columns (2-column
labels and 4-column inputs), the form would fill the 6-column content
area, thereby automatically centering itself"
Since 6 is half of 12, the form col-6 (2+4) is only going to fill half the parent col-6. If you want a narrower form in the middle use col-4 (1/3 width), and then something that adds to 12 for the labels and form input (eg. 3+9). OFC you could also use 4/8, 6/6, etc...
<div class="container-fluid">
<div class="row">
<div class="my-4 offset-4 col-4 justify-content-center align-items-center">
<form action="/some/path" method="post">
<div class="form-group row">
<label for="username" class="col-3 col-form-label">Username</label>
<div class="col-9">
<input type="text" class="form-control" id="username" name="_username" required="required" autocomplete="username">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-3 col-form-label">Password</label>
<div class="col-9">
<input type="password" class="form-control" id="password" name="_password" required="required" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<div class="col-3"></div>
<div class="col-9">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on">
<label for="remember_me" class="form-check-label">Remember me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<button class="btn btn-burnt-orange" type="submit" id="_submit" name="_submit">Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
https://www.codeply.com/go/b4FE5qflxS
Related: Center the content inside a column in Bootstrap 4
You can accomplish this by using col-6 and justify-content-center. All you have to do is setup the elements, rows and columns with bootstrap.
Here is an example of centering the form group:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="site" class="container-fluid">
<div class="row justify-content-center">
<div class="col-6" style="background: #eee;">
<!-- formgroup start -->
<form>
<div action="/some/path" class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Enter username" name="_username" required="required" autocomplete="username" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" name="_password" required="required" autocomplete="current-password" />
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="remember_me" name="_remember_me" value="on" />
<label class="form-check-label" for="remember_me">Remember me</label>
</div>
<button type="submit" class="btn btn-primary" id="_submit" name="_submit">Submit</button>
</form>
<!-- formgroup end -->
</div>
</div>
</div>
Reference these pages on the Bootstrap 4 documentation
https://getbootstrap.com/docs/4.1/layout/grid/
https://getbootstrap.com/docs/4.1/components/forms/

Styling inlined form inputs with Bootstrap 3

I'm trying to create a simple form using Bootstrap 3 where people can sign up for a small event.
On this form, they should also be able to indicate if they want one or more T-shirts, and which size(s) they want to order.
I'm not new to HTML, CSS and Javascript, but I am quite new to Bootstrap. Also while I'm a programmer by day, I'm mainly writing REST services so my design skills are fairly limited.
Using w3schools and other tutorial sites I have arrived at this:
<div class="form-group form-group-sm">
<p class="help-block">Please select the number of T-shirts per size you would like to order.</p>
<label class="col-xs-1" for="shirt-s">S</label>
<div class="col-xs-1">
<input class="form-control" type="text" id="shirt-s">
</div>
<label class="col-xs-1" for="shirt-m">M</label>
<div class="col-xs-1">
<input class="form-control" type="text" id="shirt-m">
</div>
<label class="col-xs-1" for="shirt-l">L</label>
<div class="col-xs-1">
<input class="form-control" type="text" id="shirt-l">
</div>
<label class="col-xs-1" for="shirt-xl">XL</label>
<div class="col-xs-1">
<input class="form-control" type="text" id="shirt-xl">
</div>
<label class="col-xs-1" for="shirt-xxl">XXL</label>
<div class="col-xs-1">
<input class="form-control" type="text" id="shirt-xxl">
</div>
<div class="col-xs-2"> </div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Submit</button>
</div>
See jsfiddle:
https://jsfiddle.net/tonvanbart/83nbny8h/5/
Not the prettiest in the world, but I can live with it. My main question is: why is the 'submit' button not in it's own row but inlined after the input fields? At first I thought I had to get to a total of 12 columns and I only had 10. But adding a 2-column div with a non-breaking space didn't help, and adding a <br> tag had no effect either.
Also, while I can live with this (it's for an informal, small group of people who know each other well) if anybody could give me a pointer on how to get the T-shirt size indicators closer to their respective input fields, that would be great. Thank you in advance.
Feel free to let me know if you need more information.
Here's the fixed code:
https://jsfiddle.net/ccx9x7om/1/
I added the following CSS
.row .form-group label, .row .form-group input {
display: inline-block;
}
.row .form-group input {
width: 50%;
}
button {
margin: 25px;
}
In order to use bootstrap's columns properly, you need to wrap them in a row, and wrap all rows inside either a .container or a .container-fluid. I moved the labels inside their respective .col-xs-2 then wrapped everything in the needed aforementioned divs.
Another way you could do this is by nesting your columns as to split the form in half which will greatly reduce the screen space it's using and bring your inputs closer while remaining responsive across viewports.
This is simply following the container/row/column layout that Bootstrap generally follows. See Nesting Columns.
*Note: The form-group class isn't necessary, it simply adds padding around your inputs.
See working Snippet at FullPage.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form>
<h2>Order a Shirt</h2>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="name">Name</label>
<input type="password" class="form-control" id="name" placeholder="Your Name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" placeholder="Email address (never shown)">
</div>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-xs-4 col-sm-4">
<div class="form-group">
<label for="shirt-s">S</label>
<input class="form-control" type="text" id="shirt-s">
</div>
</div>
<div class="col-xs-4 col-sm-4">
<div class="form-group">
<label for="shirt-m">M</label>
<input class="form-control" type="text" id="shirt-m">
</div>
</div>
<div class="col-xs-4 col-sm-4">
<div class="form-group">
<label for="shirt-l">L</label>
<input class="form-control" type="text" id="shirt-l">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4 col-sm-4">
<div class="form-group">
<label for="shirt-xl">XL</label>
<input class="form-control" type="text" id="shirt-xl">
</div>
</div>
<div class="col-xs-4 col-sm-4">
<div class="form-group">
<label for="shirt-xxl">XXL</label>
<input class="form-control" type="text" id="shirt-xxl">
</div>
</div>
<div class="col-xs-4 col-sm-4">
<div class="form-group">
<label>Order Now</label>
<button type="submit" class="btn btn-success btn-block btn-submit">Submit</button>
</div>
</div>
<div class="col-xs-12">
<p class="help-block">Please select the number of T-shirts per size you would like to order.</p>
</div>
</div>
</div>
</div>
</form>
</div>

How to make bootstrap form filed to 100 percent in width

I have two col divs in a row with each having two text filed while re-sizing in mobile the width of the textbox is not going to 100% and looking ugly.
Below is my bootstrap code, but in select filed the width is looks OK ..
here is the demo link see the 'Name' and 'Phone' field
http://www.responsinator.com/?url=webapplications.co.in%2Fdiamovitcarhire.com%2Fget-a-quote.html
<div class="row">
<div class="input-daterange input-group" id="datepicker">
<div class="col-md-6 col-sm-12 col-lg-6" >
<div class="form-group">
<label for="Name">Name </label>
<div class="input-group">
<input class="input-md form-control" name="Name" type="text">
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label for="phone">Phone </label>
<div class="input-group">
<input class="input-md form-control" name="phone" type="text">
</div>
</div>
</div>
</div>
</div>
What you probably want is something like this:
<div class="container">
<div class="row">
<div class="col-md-6" >
<div class="form-group">
<label for="Name">Name </label>
<input class="form-control" name="Name" type="text">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="phone">Phone </label>
<input class="form-control" name="phone" type="tel">
</div>
</div>
</div>
</div>
If you use that structure it should work like you described it.
Most likely you are using 'container' as your base. According to Bootstrap's site (search for 'container-fluid') the container-fluid class is the one setting div to full width of your viewport.

Bootstrap 3 - 2 inputs in the same line but not in the same width as one input

The title might sound tricky but here is my problem :
Inputs for "Nom" and "Prénom" are, as i want, in the same line but they are not in the same width line the first input.
Here is my code :
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label"><abbr title="Code National de l'Étudiant">CNE</abbr> <span class="important">*</span></label>
<div class="col-sm-10">
<input type="text" name="cne" class="form-control">
</div>
</div>
<div class="form-group">
<label for="nom" class="col-sm-2 control-label">Nom <span class="important">*</span></label>
<div class="col-sm-10">
<div class="col-sm-6">
<input type="text" name="nomFr" class="form-control" id="nom" placeholder="En français">
</div>
<div class="col-sm-6">
<input type="text" name="nomAr" class="form-control" id="nom" placeholder="العربية" dir="rtl">
</div>
</div>
</div>
<div class="form-group">
<label for="prenom" class="col-sm-2 control-label">Prénom <span class="important">*</span></label>
<div class="col-sm-10">
<div class="col-sm-6">
<input type="text" name="prenomFr" class="form-control" id="prenom">
</div>
<div class="col-sm-6">
<input type="text" name="prenomAr" class="form-control" id="prenom" placeholder="العربية" dir="rtl">
</div>
</div>
</div>
<div class="form-group">
<label for="dateNaissance" class="col-sm-2 control-label">Date de naissance <span class="important">*</span></label>
<div class="col-sm-10">
<input type="date" name="dateNaissance" class="form-control" id="dateNaissance">
</div>
</div>
</form>
You need to add a row class on your <div class="col-sm-10"> divs. This sets a negative padding which means the position padding set by columns allows it to line up.
Look at http://getbootstrap.com/css/#grid-nesting for info.
<div class="form-group">
<label for="nom" class="col-sm-2 control-label">Nom <span class="important">*</span></label>
<div class="col-sm-10 row">
<div class="col-sm-6">
<input type="text" name="nomFr" class="form-control" id="nom" placeholder="En français">
</div>
<div class="col-sm-6">
<input type="text" name="nomAr" class="form-control" id="nom" placeholder="العربية" dir="rtl">
</div>
</div>
</div>
Be careful how you nest your elements. You must have a new row before nesting col-*s.
<div class="col-sm-10 row">
<div class="row">
<div class="col-sm-6">
<input type="text" name="nomFr" class="form-control" id="nom" placeholder="En français">
</div>
<div class="col-sm-6">
<input type="text" name="nomAr" class="form-control" id="nom" placeholder="العربية" dir="rtl">
</div>
</div>
</div>
Every container and col-* has a 15px padding left and right. The row element has margin left and right set to -15px to compensate. so container > row > col > row >col etc
Actually you don't need to have a row for each set of col- elements, as the .form-group class is the same as .row with the addition of a bottom-margin - you could argue that semantically it's better... Meh.
The main issue is you are nesting 2 x 6-column-span elements in a 10-column-span element, and you have already used up 2 columns with the label, so it's all wrong.
As you probably know, Bootstrap uses a 12 column grid system, so if you create an element and apply col-sm-2 then you have 10 columns left. If you have 2 elements, each spanning 6 columns, it's not going to work.
What you can do is lose the extra <div class="col-sm-10"> and change your 2 inputs to span 5 cols each:
<div class="form-group">
<label for="nom" class="col-sm-2 control-label">Nom <span class="important">*</span></label>
<div class="col-sm-5">
<input type="text" name="nomFr" class="form-control" id="nom" placeholder="En français">
</div>
<div class="col-sm-5">
<input type="text" name="nomAr" class="form-control" id="nom" placeholder="العربية" dir="rtl">
</div>
</div>
That will give you what you really want - each input field in 2 column areas aligned to the edges of the fields in single column areas.
Note: I use form-group here because the bottom margin pads out the rows and looks nice IMO.

Bootstrap form-inline indenting

So I'm working in bootstrap for the first time and I'm making a form, like so:
<div class="input-group col-xs-2">
<label>Voornaam:</label>
<input type="text" class="form-control" placeholder="Voornaam">
</div>
<div class="input-group col-xs-2">
<label>Achternaam:</label>
<input type="text" class="form-control" placeholder="Achternaam">
</div>
<div class="input-group">
<label for="adresCaptain" class="control-label">Straatnaam + nr:</label>
<div>
<div class="form-inline">
<div class="form-group col-xs-9">
<input type="text" class="form-control" id="streetCaptain" placeholder="Straat"/>
</div>
<div class="form-group col-xs-3">
<input type="number" class="form-control" id="houseNrCaptain" placeholder="Nr"/>
</div>
</div>
</div>
</div>
Now, I've got a problem with the indentation of the "form-inline" part. For some reason, it's more indented than the other parts of the form.
image of result: http://puu.sh/g874J/2579b314e4.png
Any idea why this is the case and how I can make it so that the indentation is the same for every part of the form?
Your col-xs-X class adds an extra padding to div.