Make a Horizontal Search Form fill Column Space Bootstrap - html

I'm using bootstrap to create a webpage and I've got two rows inside a fluid container. I've created a horizontal search area (form) above the second row. It does not expand to the entire width of the column, and I cannot figure out why or what class I have to apply to get it to expand to the width of the entire column.
Here is my code:
<div class ="container-fluid">
<div class ="row" style ="margin-right: 15%"> <!-- Row for location search -->
<div class="col-sm-4" style="max-width:400px;">
</div>
<div class="col-sm-8"> <!-- For direction search button -->
<form action="" class="form-inline" role="search">
<div class="form-group-stylish">
<button class="btn btn-primary" type="submit" style="max-width: 120px;">Search</button>
<input type="text" class="form-control" placeholder="Enter Start Location">
<input type="text" class="form-control" placeholder="Enter Destination">
</div>
</form>
</div>
</div> <!-- End row for location search -->
<div class = "row top-buffer-small" style="margin-right: 15%">
<div class = "col-sm-4" style="max-width:400px;">
<div class ="img" style="border: 5px solid #e83724; border-radius: 20px; height: 100px; background-color: white;">
<h2 class ="text-center" style="margin-top: 5px;">Filter Search Results</h2>
</div>
</div>
<div class="col-sm-8">
<div class="embed-responsive embed-responsive-4by3">
<iframe class="embed-responsive-item" src="https://www.google.com/maps/embed/v1/directions?origin=Madison+WI
&destination=Milwaukee+WI&key=XXXXXXXX">
</iframe>
</div>
</div>
</div> <!-- End Row for Search filters and map-->
</div> <!-- End container for search filters and map -->
Here is a screenshot of what it currently looks like (as I've omitted my API key) and an arrow drawn to show what I would like to accomplish. I would like the start and end location search boxes to remain the same size, just both expanded the same amount to fill the remainder of the column.
Screenshot of what page currently looks like:
How can I accomplish this? Thanks!

Try to devide button, both input into three columns as col-sm-8 has been defined above:
The value of col-sm- depends on what you need. You can set it free.
<div class="form-group-stylish">
<div class="col-sm-1">
<button class="btn btn-primary" type="submit" style="max-width: 120px;">Search</button>
</div>
<div class="col-sm-4">
<input type="text" class="form-control" placeholder="Enter Start Location">
</div>
<div class="col-sm-7">
<input type="text" class="form-control" placeholder="Enter Destination">
</div>

Do two changes.
1. Remove class form-inline from form tag.
Inputs and selects have width: 100%; applied by default in Bootstrap. Within inline forms, it reset to width: auto;. Depending on your layout, additional custom widths may be required.
2. Add row and column to your form structure.
<form action="" role="search">
<div class="form-group-stylish row">
<div class="col-sm-2">
<button class="btn btn-primary" type="submit" style="max-width: 120px;">Search</button>
</div>
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Enter Start Location">
</div>
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Enter Destination">
</div>
</div>
</form>
Make sure you add row before using col. Otherwise your code may run, but you are not following BootStrap standards( .container>.row>.col ).

Related

Horizontally aligning HTML input fields correctly for Bootstrap 3 and responsiveness

I have a simple web page, using Bootstrap 3, where I am centering everything and then I have 2 input fields and a button. This I would like to get aligned in a nice looking manner and be responsive but for some reason I cannot get it working. Maybe I already know the problem - I don't understand the Bootstrap grid system good enough ;-)
I have this HTML code:
<div class="container">
<div class="row">
<!-- Do not use the first 4 columns as I want it centered -->
<div class="col-md-4">
</div>
<!-- Center the content in the middle 4 columns -->
<div class="col-md-4">
<div class="form-group form-inline form-horizontal form-group-lg">
<div>
<!-- Input 1 -->
<div class="form-group">
<input type="text" class="form-control input-lg" data-provide="typeahead" autocomplete="off" placeholder="Placeholder 1" />
</div>
<!-- Input 2 -->
<div class="form-group">
<input type="email" class="form-control input-lg" placeholder="Placeholder 2" />
</div>
<!-- Submit button -->
<button class="btn btn-lg btn-primary" type="button">Button 1 2 3</button>
</div>
</div> <!-- <div class="form-group form-inline form-horizontal form-group-lg"> -->
</div> <!-- <div class="col-md-4"> -->
<!-- Do not use the last 4 columns as I want it centered -->
<div class="col-md-4">
</div>
</div> <!-- <div class="row"> -->
</div> <!-- <div class="container"> -->
The above HTML code gives this result, which I do not want.
I have this:
Ideally I would like the 3 things (2 x input + button) to be gathered at the center of the screen with maybe 10 pixels betweem them.
I want this:
I have this JSFiddle demo, https://jsfiddle.net/33am99hj/
I have also tried excluding the <div class="container"> and <div class="row"> and then everything is at one line but then the input fields are overlapping and I cannot see them completely:
Any ideas how I can get the content nicely centered with a little spacing between them and still be responsive (stacked when they cannot fit the screen)?
SOLUTION as mentioned by Marko Manojlovic:
I ended up with this JSFiddle solution, https://jsfiddle.net/ducbLsbc/
nicely formatted question,
What you first need to do is make one subgrid under yours <div class="col-md-4">thats responsible for holding your form. With this new subgrid in place, you can then control the inputs width and responsive variations. With this in place, you can set the width and responsive widths to the sizes you need:
Sample code:
<div class="row">
<div class="col-xs-12 col-sm-4">
<input type="text" class="form-control input-lg" data-provide="typeahead" autocomplete="off" placeholder="Placeholder 1" />
</div>
<div class="col-xs-12 col-sm-4">
<input type="email" class="form-control input-lg" placeholder="Placeholder 2" />
</div>
<div class="col-xs-12 col-sm-4">
<button class="btn btn-lg btn-primary btn-block" type="button">Button 1 2 3</button>
</div>
</div>
Class form-control on input field is responsible for matching the width of the input with your parent element (in sample case: col-xs-12 and col-sm-5)
Classes col-*-* will also add the spacing between inputs you need.
Hope this helps.

Multiple textboxes in a single row in Bootstrap

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)" />

Bootstrap fields in a column

I was wondering what I have done wrong here: http://www.bootply.com/bURS2tSeSU
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Contact Us</div>
<div class="panel-body">
<form class="form-horizontal">
<fieldset>
<!-- Text input-->
<div class="form-group">
<input id="subject" name="subject" type="text" placeholder="Subject" class="form-control input-md">
<span class="help-block">help</span>
</div>
<!-- Textarea -->
<div class="form-group">
<textarea class="form-control" id="message" name="message">default text</textarea>
</div>
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Button</button>
</fieldset>
</form>
</div>
</div>
</div>
My panel-body should have padding but instead it seems like the padding isn't taking effect for the form fields. Can anyone tell me why this might be happening and how I can get my fields to sit within the panel-body and not right up to the edges.
Your problem is that you stuck everything into a column. Each component in a column take up equal width (specified by you as col-md-4). I replaced your column with a row, and wrapped everything by a container (which you always need to do).
Code
<div class="container">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">Contact Us</div>
<div class="panel-body">
<fieldset>
<!-- Text input-->
<div class="form-group">
<input id="subject" name="subject" type="text" placeholder="Subject" class="form-control input-md"> <span class="help-block">help</span>
</div>
<!-- Textarea -->
<div class="form-group">
<textarea class="form-control" id="message" name="message">default text</textarea>
</div>
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Button</button>
</fieldset>
</div>
</div>
</div>
Documentation:
Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding.
BOOTPLY
You are using the form-group. According to bootstrap documentation:
Use Bootstrap's predefined grid classes to align labels and groups of form controls in a horizontal layout by adding .form-horizontal to the form. Doing so changes .form-groups to behave as grid rows, so no need for .row.
But in turn this means, that you will have to add columns for your input fields:
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Contact Us</div>
<div class="panel-body">
<form class="form-horizontal" role="form">
<fieldset>
<!-- Text input-->
<div class="form-group">
<div class="col-md-12">
<input id="subject" name="subject" type="text" placeholder="Subject" class="form-control input-md"> <span class="help-block">help</span>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<div class="col-md-12">
<textarea class="form-control" id="message" name="message">default text</textarea>
</div>
</div>
<!-- submit button -->
<div class="form-group">
<div class="col-md-12">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Button</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
See here http://www.bootply.com/rSLgYayGaO

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>

Twitter Bootstrap - Two Column layout for <form>

In Bootstrap 2.3, is there a standardized way to have a two-column layout for an HTML <form> with labels/inputs/actions? I don't see any in the documentation.
An example image of what I want: http://i.imgur.com/3o6IoN4.png
As an aside, I need there to be a solid background color that spans the entire width of the div.span12 or other enclosing container. Having two .span6 causes a break in the background color in the center (which I suppose can be fixed by wrapping the two .span6 in a div.clearfix with the background class applied?
Easy stuff. Bring the bootstrap row within a parent div and set the background of that div to a color of your choosing.
The Markup:
<div id="background-color">
<form id="form1" name="form1" method="post" action=""><!-- START THE FORM -->
<div class="row-fluid">
<div class="span6"> <!-- FIRST COLUMN -->
<label>First Name</label>
<label for="textfield"></label>
<input type="text" />
<label>Last Name</label>
<label for="textfield"></label>
<input type="text" />
</div>
<div class="span6"> <!-- SECOND COLUMN -->
<label>Other</label>
<label for="textfield"></label>
<input type="text" />
<label>Fields</label>
<label for="textfield"></label>
<input type="text" />
<input type="submit" name="button" id="button" value="Submit" />
</form> <!-- END THE FORM -->
</div>
</form>
</div> <!-- End row -->
</div> <!-- END BACKGROUND -->
The CSS:
#background-color {background-color: #CCC;}
I hope this helps
To my understanding for Bootstrap 3 these changes are required;
all code sitting in container to access grid system info here
span to col for new version
use device class as suits your requirements info here
labels and controls wrapped in form-group for spacing info here
form class to form-horizontal removes the need for row divs (i have used nested columns without rows, seems to display correctly with form-horizontals function)
panel used to frame the form as pictured
<div class="container">
<div class="panel panel-default" style="background-color: #CCC">
<div class="panel-body">
<form id="form1" name="form1" method="post" action="" class="form-horizontal"><!-- START THE FORM -->
<div class="col-sm-6"> <!-- FIRST COLUMN -->
<div class="form-group">
<label for="inputFirstname" class="col-sm-4 control-label">First Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputFirstname" placeholder="First Name">
</div>
</div>
<div class="form-group">
<label for="inputLastname" class="col-sm-4 control-label">Last Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputLastname" placeholder="Last Name">
</div>
</div>
</div>
<div class="col-sm-6"> <!-- SECOND COLUMN -->
<div class="form-group">
<label for="inputEmail" class="col-sm-4 control-label">Email</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputUsername" class="col-sm-4 control-label">Username</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="inputUsername" placeholder="Username">
</div>
</div>
</div>
</form> <!-- END THE FORM -->
</div>
</div><!-- END PANEL -->
</div>