Bootstrap grid layout: inputs expand 100% width at the halfway point - html

So I'm trying to create a simple responsive form using bootstrap grids, but it is being very tricky for me. You can ignore most of what I'm posting (the coldfusion for starters, is redundant) but pay attention to the grid classes!
<div id="custom-wrapper">
<div class="row">
<div class="col-lg-12">
<h1>Create Definitions</h1>
<div style="#display#" class="error-box alert alert-#alert#">#alertMsg#</div>
</div>
<!-- /.col-lg-12 -->
<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-lg-10">
<form class="form-horizontal" id="addDef" action="index.cfm?group=#URL.group#" method="POST">
<div class="form-group"> <!--- state select --->
<label for="state" class="col-lg-3 control-label">Assign to State:</label>
<div class="col-lg-7">
<select id="states" name="states" class="form-control">
<cfloop query="state">
<option value="#state.ID#" name="state">#state.StateName#</option>
</cfloop>
</select>
</div>
</div>
<div class="form-group"> <!--- state select --->
<label for="sluglist" class="col-lg-3 control-label">Assign to Question:</label>
<div class="col-lg-7">
<select id="slugList" name="slugs" class="form-control">
<option selected>--- Choose a Slug ---</option>
<cfloop query="questions">
<option value="#questions.ID#" name="state">#questions.slug#</option>
</cfloop>
</select>
</div>
</div>
<div class="form-group" id="xhrHidden" style="display:none"> <!--- question text --->
<label for="term" class="col-lg-3 control-label">Question Text:</label>
<div class="col-lg-7">
<span id="questionText"></span>
</div>
</div>
<div class="form-group"> <!--- rich text div for definition --->
<label for="term" class="col-lg-3 control-label">Text Entry:</label>
<div class="col-lg-7">
<textarea name="term" id="term"></textarea>
<div>Define a term or phrase on a state by state basis.</div>
</div>
</div>
<div class="form-group"> <!--- group select --->
<label for="state" class="col-lg-3 control-label">Group: #group.GroupName#</label>
<div class="col-lg-7">
<div>#group.GroupName#</div>
</div>
</div>
<div class="form-group"> <!--- submit button --->
<label for="submit" class="col-lg-3 control-label"></label>
<div class="col-lg-7">
<input type="submit" class="btn btn-primary" id="submitbutton" value="Create Definition" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
What happens is they start out at about half the screen size, and when you shrink your browser, the grids shrink, and then suddenly, at about 50%, the inputs expand to what looks like 100% width, and then the next media query kicks in and it goes into normal sizing.
Could somebody explain why my grids would expand at about the halfway point?
Basically I'm having trouble using grids and having even widths across my elements, but it seems like the elements shouldn't be 100% of the grid, otherwise it takes up the whole page and is ugly.

Why my grids would expand at about the halfway point?
This is because you have only used .col-lg-* grid classes, which styles the columns for devices having large screens and leaves the elements untouched on lower screens.
Therefore the block-level elements such as <div> would fill the entire space of their parent.
Consider using col-md-* and/or col-sm-* classes as well in order to specify the width of columns on smaller screens, with the following order:
<div class="col-xs-* col-sm-* col-md-* col-lg-*">
For further info you could refer to my answer here:
What happens when grid classes apply to devices with smaller breakpoint size

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.

Responsive form that switches between 1 or 2 controls per line

I am trying to create a responsive form using Bootstrap.
When the page is of medium width or larger, I would like the date range controls to share the same line:
When the page is small, I would like the two date controls to be placed on separate lines:
The problem is - if I put the Start and End in the same form group, it doesn't space well when on separate lines:
But then, if I put the Start and End in different form groups, they are always on separate lines, even when the screen is wide.
Does bootstrap provide a way to deal with this, or am I going to have to write my own custom styling rules?
Here is the complete code as a plunk:
http://plnkr.co/edit/XZYEU73ov7BBaMQmO7ec?p=preview
<form class="form-horizontal">
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-8">
<div class="form-group">
<label class="col-sm-2 control-label">
Video
</label>
<div class="col-sm-10">
<input class="form-control" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">
Start
</label>
<div class="col-sm-10 col-md-4">
<input class="form-control" type="date" />
</div>
<!-- If I start a new form group here, it forces a new line -->
<label class="col-sm-2 control-label">
End
</label>
<div class="col-sm-10 col-md-4">
<input class="form-control" type="date" />
</div>
</div>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<button class="btn btn-primary">
Generate Report
</button>
</div>
</div>
</form>
You could add a custom CSS class and add it too the one you want the margin under (change max width as appropriate).
#media all and (max-width: 991px){
.margin-bottom {
margin-bottom:15px;
}
}
http://plnkr.co/edit/kZza07SVcYa6QfC8YwpU?p=preview
If you are using Example 1 in http://plnkr.co/edit/XZYEU73ov7BBaMQmO7ec?p=preview, use the following CSS for responsive View :
#media all and (max-width: 991px){
.col-sm-10{
margin-bottom: 15px;
}
}

Make a Horizontal Search Form fill Column Space Bootstrap

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 ).

Row spanning in Bootstrap Grid design

I am using the Grid layout in Bootstrap.
How do I make a particular control(say text area) span for 3 rows in this grid design?
Is it possible with Grid layout?
You essentially want to use a nested grid or a form group.
First, split the page into two columns, the left with more than one row and the right with only one row. In the provided example, I demonstrate how you could use a form group in the left column to get the labels/inputs exactly as in your diagram.
<div class="row">
<!-- Left Column -->
<div class="col-sm-6">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-3 control-label">Input 1</label>
<div class="col-sm-9">
<input type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Input 2</label>
<div class="col-sm-9">
<input type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Input 3</label>
<div class="col-sm-9">
<input type="text" class="form-control">
</div>
</div>
</form>
</div>
<!-- Right Column -->
<div class="col-sm-6">
<textarea class="form-control" rows="3"></textarea>
</div>
</div>
See this working Plnkr example
Note that the plnkr needs to be wide enough to not apply the responsive layout and stack
If instead you wanted to use a nested grid to get the same effect, you would just define a new grid with rows/columns inside the left column.
I did not test this, but try something like this:
<div class="row">
<div class="col-md-9">
<div class="col-md-12">.col-md-12</div>
<div class="col-md-12">.col-md-12</div>
<div class="col-md-12">.col-md-12</div>
</div>
<div class="col-md-3">.col-md-3</div>
</div>
This uses the nested columns, like #user3711852 suggested.

Twitter bootstrap: Label partly hidden behind text input when browser window width is not 100%

I have this problem with all the labels/inputs in my code. When my browser is in full screen it works fine, but when I minimize it even a bit, the input field steps over the label.
How do I avoid this?
<form class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label" for="input-username">Username:</label>
<div class="col-xs-4">
<input id="input-username" class="form-control" type="text" placeholder="Username.." />
</div>
</div>
Here's a jsfiddle for an example http://jsfiddle.net/2MdFf/
PS: Same goes for buttons: http://jsfiddle.net/9q949/
<div id="user-edit-buttons" class="form-group">
<div class="col-xs-1">
<button type="button" class="btn btn-danger" onclick="cancelUserEdit()">Avbryt</button>
</div>
<div class="col-xs-1">
<button type="button" class="btn btn-success" onclick="saveUser()">Lagre</button>
</div>
</div>
This is precisely why Bootstrap offers col sizing for multiple screens widths. Your column contents are overflowing their containers due to the sizing of those elements.
<form class="form-horizontal">
<div class="form-group">
<label class="col-xs-3 col-sm-3 col-md-2 col-lg-1 control-label" for="input-username">Username:</label>
<div class="col-xs-4">
<input id="input-username" class="form-control" type="text" placeholder="Username.." />
</div>
</div>
They expect you to use different column sizes to make your elements work well in the different screen sizes.