Multiple textboxes in a single row in Bootstrap - html

I'm using Bootstrap to try and place 2 textboxes next to a label, all on a single row, however, I can't seem to get everything to line up properly.
I'm working on trying to get the "Domestic" row working first. The other rows look exactly how I want them to look, but that's only because I cheated and added a style of "width: 49%" to them. Doing this, however, breaks the fully responsive nature of the textboxes, which I want to keep.
You'll notice that for the "Domestic" row, that the label doesn't line up with the rows below it, and neither do either of the textboxes. This is my code for the "Domestic" row -
<div class="row">
<div class="form-horizontal">
<div class="form-group col-md-12 col-xs-12">
<div class="col-md-4 col-xs-12">
<label class="control-label">Domestic</label>
</div>
<div class="col-md-4 col-xs-12">
<input id="percentage" class="form-control" type="text" placeholder="Percentage">
<span class="input-group-addon">
<i class="glyphicon glyphicon-remove-circle"></i>
</span>
</div>
<div class="col-md-4 col-xs-12">
<input id="flat" class="form-control" type="text" placeholder="Flat (eg. 0.33)">
<span class="input-group-addon">
<i class="glyphicon glyphicon-remove-circle"></i>
</span>
</div>
</div>
</div>
Things go even more pear shaped when I run validation on the form and start displaying those input-group-addons -
All I'm essentially trying to do is split the row into thirds, 1 third for the label, 1 third for the first textbox and 1 third for the second textbox (and then, if that works, hopefully I can get it working for 1 row per control on xs displays).
Any ideas?
Edit: As requested, here is my code for the "Amex" row -
<div class="row">
<div class="form-group col-md-12 col-xs-12">
<label class="col-md-4 col-xs-12 control-label">Amex</label>
<div class="input-group col-md-8 col-xs-12 form-inline">
<div class="input-group" style="width: 49%;">
<input id="amexPercentage" class="form-control" type="text" placeholder="Percentage">
<span class="input-group-addon">
<i class="glyphicon glyphicon-remove-circle"></i>
</span>
</div>
<div class="input-group" style="width: 49%;">
<input id="amexFlat" class="form-control" type="text" placeholder="Flat (eg. 0.33)">
<span class="input-group-addon">
<i class="glyphicon glyphicon-remove-circle"></i>
</span>
</div>
</div>
</div>

The form you're creating is tricky. There's no examples in the documentation of a .form-horizontal with nested columns inside the widest column. You were missing the correct html for the input-group too. Since there is a lot of wrappers, it's good to indent your code and comment it.
What you need to do is use grid system inside the widest column and since you want two 50% columns, you would use just a .col-X-6 at the breakpoint you desire. In this case you want the columns side by side at the col-md min-width, which is 992px.
Also, often times the col-X-12 class is not necessary. An element will be 100% width below the last column class used. An element with .col-md-4 will be 100% under that, you don't have to tell it to be 100% by adding an extra and unecessary class col-sm-12 or col-xs-12
Demo: https://jsbin.com/yojoci
CSS
This adds some vertical space when the form stacks at below the min-width class choice.
#media (max-width:991px) {
.form-horizontal.custom-form .form-group .row [class*=col-]:first-child {
margin-bottom: 5px
}
}
HTML
<div class="container">
<form class="form-horizontal custom-form" role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Domestic</label>
<div class="col-sm-10">
<div class="row">
<div class="col-md-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Text One">
<span class="input-group-addon">#</span>
</div>
<!-- /.input-group -->
</div>
<!-- /.col-md-6 -->
<div class="col-md-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Text Two">
<span class="input-group-addon">#</span>
</div>
<!-- /.input-group -->
</div>
<!-- /.col-md-6 -->
</div>
<!--/.row -->
</div>
<!--/.col-sm-10 -->
</div>
<!--/.form-group -->
<div class="form-group">
<label class="col-sm-2 control-label">Amex</label>
<div class="col-sm-10">
<div class="row">
<div class="col-md-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Text Three">
<span class="input-group-addon">#</span>
</div>
<!-- /.input-group -->
</div>
<!-- /.col-md-6 -->
<div class="col-md-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Text Four">
<span class="input-group-addon">#</span>
</div>
<!-- /.input-group -->
</div>
<!-- /.col-md-6 -->
</div>
<!--/.row -->
</div>
<!--/.col-sm-10 -->
</div>
<!--/.form-group -->
<div class="form-group">
<label class="col-sm-2 control-label">Premium</label>
<div class="col-sm-10">
<div class="row">
<div class="col-md-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Text Five">
<span class="input-group-addon">#</span>
</div>
<!-- /.input-group -->
</div>
<!-- /.col-md-6 -->
<div class="col-md-6">
<div class="input-group">
<input type="text" class="form-control" placeholder="Text Six">
<span class="input-group-addon">#</span>
</div>
<!-- /.input-group -->
</div>
<!-- /.col-md-6 -->
</div>
<!--/.row -->
</div>
<!--/.col-sm-10 -->
</div>
<!--/.form-group -->
</form>
</div>
<!--/.container (DON'T NEST) -->

Instead of trying to hack the three column layout together, I would use a framework already built to handle it. I recommend Toast by Dan Eden: https://github.com/daneden/Toast.
It will help you create a three column layout that's responsive and doesn't break.
As he said in the docs, link this in your head:
<link rel="stylesheet" href="css/toast/grid.css">
Then create your layout with the following format:
<div class="container">
<div class="grid">
<div class="grid__col grid__col--1-of-4">
</div>
<div class="grid__col grid__col--3-of-4">
</div>
<div class="grid__col grid__col--6-of-12">
</div>
</div>
</div>
There are more specific instructions in his description.

Make sure you close your input tags correctly. Currently you are missing the closing tag />. Please also post your html for the next two rows as well.
<input id="flat" class="form-control" type="text" placeholder="Flat (eg. 0.33)" />

Related

Bootstrap grid columns does not seem to be working properly

I'm using Bootstrap 3 and I have set up this grid for my webpage:
<div class="container">
<div class="header">
<div class="top-nav">
<div class="row">
<div class="col-1">
<img src="https://sitename.com/logo.jpg">
</div>
<div class="col-7 mid-nav">
<!-- Search box & Navbar comes here -->
</div>
<div class="col-1" style="margin-top:30px !important;">
<i class="fa fa-shopping-cart fa-4x sabad-kharid"></i>
</div>
<div class="col-3">
<form method="POST" action="">
<div class="form-group">
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
And the result is shown in this:
As you can see the Bootstrap form does not appear in the col-3 class and it appears at the below of this row. However it should be placed at the left side in the div with class of col-3.
So what's going wrong here? How can I solve this issue?
You should use col-xs-1 col-xs-7 col-xs-3 in your class (instead col-7) or any size and display what you want.

Button not inlined on smaller devices

I have a form that looks like this (on a big device, e.g. pc monitor)
that is as it should be. On smaller devices it however looks like this:
the button is no longer in the same line as the input. My code looks like this:
<div class="form-group ">
<label class="col-md-2 control-label">Title</label>
<div class="col-md-10">
<div class="row">
<div class="col-md-10">
<input id="title" class="form-control" placeholder="Title" autocomplete="off" name="title" type="text" value="">
</div>
<div class="col-md-2">
<a id="btn-verify" class="btn btn-primary pull-right">Verify</a>
</div>
</div>
</div>
</div>
How can I ensure that it also is aligned correctly when using smaller devices?
PS: Bootstrap is being used
Your columns are col-md, which means that when the screen width gets below 992px, the columns will take up the full width of the page. So if you want them to stay inline, then add col-xs classes with the column sizes that you need.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group ">
<label class="col-md-2 control-label">Title</label>
<div class="col-md-10">
<div class="row">
<div class="col-xs-10">
<input id="title" class="form-control" placeholder="Title" autocomplete="off" name="title" type="text" value="">
</div>
<div class="col-xs-2">
<a id="btn-verify" class="btn btn-primary pull-right">Verify</a>
</div>
</div>
</div>
</div>
Both the input and button need to be set to display: inline, and they should be placed in the same column. Below works and should satisfy your needs:
<div class="form-group ">
<label class="col-md-2 control-label">Title</label>
<div class="col-md-10">
<div class="row">
<div class="col-md">
<input id="title" class="form-control d-inline w-70 float-left" placeholder="Title" autocomplete="off" name="title" type="text" value="">
<a id="btn-verify" class="btn btn-primary float-left d-inline">Verify</a>
</div>
</div>
</div>
</div>
Have you tried stacking the bootstrap col classes?
The lg / md / sm all target different screen size thresholds. Using multiples should help you define the space it should take up in a given scenario. I would say you can steal some real-estate from that input.
You could also consider putting them in the same div.
Your code modified with stacked col classes:
<div class="form-group ">
<label class="col-md-2 control-label">Title</label>
<div class="col-md-10">
<div class="row">
<div class="col-md-10 col-sm-6">
<input id="title" class="form-control" placeholder="Title" autocomplete="off" name="title" type="text" value="">
</div>
<div class="col-md-2 col-sm-6">
<a id="btn-verify" class="btn btn-primary pull-right">Verify</a>
</div>
</div>
</div>
</div>

Bootstrap 3 making nested rows

When making nested columns with bootstrap in asp.net using webforms, how would you span the entire child?
Example:
<div class="row">
<div class="col-md-3">
<div class="row">Stuff</div>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-6">
stuff
</div>
<div class="col-md-6">
stuff
</div>
</div>
<div class="row">
<div class="col-md-12">
stuff
</div>
</div>
</div>
</div>
Here is my exact code:
<div class="row" style="margin-top: 5px">
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon" id="">Destination City:</span>
<input type="text" class="form-control" id="DestinationCity" runat="server" placeholder="" aria-describedby="basic-addon1">
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon" id="">ETA:</span>
<input type="text" class="form-control" id="ETA2" runat="server" placeholder="" aria-describedby="basic-addon1">
</div>
</div>
</div>
<div class="row" style="margin-top: 5px">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon" id="">B/L#:</span>
<input type="text" class="form-control" id="BL" runat="server" placeholder="" aria-describedby="basic-addon1">
</div>
</div>
</div>
I am trying to make 2 columns of 6 with a column of 12 underneath it. The second column will not span the entire length of the two 6s.
I think I am missing something fundamental about Bootstrap3's gridding system.
Link to image:
https://sutong-my.sharepoint.com/personal/joseph_sutongctr_com/_layouts/15/guestaccess.aspx?docid=1070ed3a0aabe43739b7cdda19e136793&authkey=AZFGucSF7ReMr4cvabz6fDQ
You HTML work perfectly as to what you wanted... 2 column followed by 1 columns spanning the entire page. You need to check if another div is wrapping it causing it to behave differently. Try to comment your start and ending div, you'd be surprised how many of us get confused.
Problem turned out to be a limit Visual Studio puts in Site.css
/* Set widths on the form inputs since otherwise they're 100% wide */
input,
select,
textarea {
max-width: 280px;
}
Answer found in Stack Question

Bootstrap align inputs side by side

I am trying to align two inputs side by side using bootstrap. Testing of regular divs as follows works great:
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 col-md-offset-4">.col-md-4 .col-md-offset-4</div>
</div>
But this always pushes to the second input below the first.
<div class="row">
<div class="col-md-2 input-group">
<span class="input-group-addon">Income $</span>
<input type="number" id="income" class="form-control" placeholder="0">
<span class="input-group-addon">.00</span>
</div>
<div class="col-md-2 col-md-offset-2 input-group">
<span class="input-group-addon">Mortgage Payment $</span>
<input type="number" id="mortgagepayment" class="form-control" placeholder="0">
<span class="input-group-addon">.00</span>
</div>
</div>
Any clues?
As in given HTML there is no <form> element.
here is the
Demo using .controls-row and .control-group
<div class="container">
<div class="controls-row row">
<div class="control-group col-md-6">
<div class="input-group">
<span class="input-group-addon">Income $</span>
<input type="number" id="income" class="form-control" placeholder="0">
<span class="input-group-addon">.00</span>
</div>
</div>
<div class="control-group col-md-6">
<div class="input-group">
<span class="input-group-addon">Mortgage Payment $</span>
<input type="number" id="mortgagepayment" class="form-control" placeholder="0">
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
</div>
You should use the "form-inline" Bootstrap class to achieve this:
<form class="form-inline">
<div class="form-group">
<div class="form-group">
<div class="input-group" style="width: 220px;">
<span class="input-group-addon">Income $</span>
<input type="number" id="income" class="form-control" placeholder="0">
<span class="input-group-addon">.00</span>
</div>
</div>
<div class="form-group">
<div class="input-group" style="width: 250px;">
<span class="input-group-addon">Mortgage Payment $</span>
<input type="number" id="mortgagepayment" class="form-control" placeholder="0">
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
</form>
Take a look at it HERE
I think you've asked a sort of loaded question, but I'll do my best to help.
After following the BS3.x docs online, I noticed you didn't wrap your form elements in a form-x class. That usually helps with their custom CSS for form elements. Following BS convention, you're missing an outer wrapper form-group. Lastly, because your beginning label(s) are different lengths (ie Mortgage Payment), wrapping them in a grid container .col-md-2 might not render the way you intend. Regardless, changing the column class is easy to do, so that is for you to decide. Remember that BS has media queries, so how it shows for you might be different depending on device and viewport width.
All that said, I've got this fiddle that should help you.
HTML
<div class="container">
<div class="row">
<form class="form-inline">
<div class="form-group col-md-6">
<div class="input-group">
<span class="input-group-addon">Income $</span><input type="number" class="form-control" /><span class="input-group-addon">.00</span>
</div>
</div>
<div class="form-group col-md-6">
<div class="input-group">
<span class="input-group-addon">Mortgage Payment $</span><input type="number" class="form-control" /><span class="input-group-addon">.00</span>
</div>
</div>
</form>
</div>
http://jsfiddle.net/5webN/

Bootstrap rows and text

I am creating a form which is horizontal and want to put a full word in between the two columns as below. If I use another tag it creates too much padding on either side of this word, and if I just put in a label or a plain text character surrounded by no tags, it ruins the position of the domain box. How can I make this work without overwriting the styles in the bootstrap.css?
I would like the form to be completely horizontal.
<div class="row">
<label for="www" class="col-sm-1 control-label">
Label1
</label>
<div class="col-sm-5">
<input type="text" class="form-control" />
</div>
<div class="col-sm-2">
<input type="text" class="form-control" />
</div>
<!-- Word to go here-->
<div class="col-sm-3">
<button type="submit" class="btn btn-primary">go</button>
</div>
</div>
</div>
Thanks in advance
You can try to follow bootstrap's 12 col grid system and specify one column col-sm-1 for the word, so that all columns add up to 12.
http://jsfiddle.net/bRh2z/show
http://jsfiddle.net/bRh2z/
<div class="row">
<label for="www" class="col-sm-1 control-label">Label1</label>
<div class="col-sm-5">
<input type="text" class="form-control" />
</div>
<div class="col-sm-2">
<input type="text" class="form-control" />
</div>
<div class="col-sm-1">woooord</div>
<div class="col-sm-3">
<button type="submit" class="btn btn-primary">go</button>
</div>
</div>