I have a basic Bootstrap input group with an input and button. Everything looks fine when the browser is a "normal" width. However when I extend it to a 2nd monitor there is a space that appears between the input control and the button. Looked around, but I have been unable to find a solution that will keep these together in a way similar to how the btn-group works.
Here's my code:
<div class="row">
<div class="col-md-2 col-md-offset-1">
<div class="input-group">
<input id="SearchText" class="form-control" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</div>
Thanks in advance!
Update:
After messing with this a little more, it appears it has something to do with the column attributes. If I make the outer div col-md-1 instead, it won't create the space. However this makes the input too small for what I need it for. Also, I'm guessing that if I extended the browser far enough the space would reappear.
Found a solution that appears to work so I thought I'd share it in case others have a similar issue.
After looking at this more, I discovered that the separation of the input from the button was happening whenever the input control reached its maximum width. In order to maintain the desired proportion dictated by the column attribute tags it created a space between the input and the button (why it doesn't just add blank space after the button, I don't know). There are two ways I found to accomplish what I was wanting:
The first is to directly adjust the maximum width of the input control. This allows the input control to expand and fill the extra space. This can be done in a number of places (css stylesheet, jquery/javascript, or in the tag itself in the html). I went ahead and included it in the stylesheet.
The second way is to include a col-lg-* attribute that is smaller than the col-md-* attribute. This reduces the proportion of the size of the input control in relation to the screen and reduces the likelihood it will reach it's maximum width (it also keeps your input control from expanding nearly as much). (Note: if you use this method I would suggest adjusting the minimum width of your input controls to keep a more consistent size).
In the end I ended up using both methods to keep my input controls about the same size and ensure that someone would have to use a ridiculously large monitor to separate the input and button.
CSS:
input.form-control {
max-width: 400px;
min-width: 200px;
}
HTML:
<div class="row">
<div class="col-md-2 col-md-offset-1 col-lg-1">
<div class="input-group">
<input id="SearchText" class="form-control" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</div>
Hope this helps someone
Related
<div class="row mb-3">
<div class="col-6">
<form autocomplete="off" action="/action_page.php">
<div class="autocomplete" >
<input type="text" id="startLocation" class="form-control" placeholder="von Bahnhof / Haltestelle / Adresse" tabindex="-1">
</div>
</form>
</div>
<div class="col-6">
<input type="text"id="destination" class="form-control" placeholder="nach Bahnhof / Haltestelle / Adresse" tabindex="-1">
</div>
</div>
I want my two text inputs to be the same with and toghther fill the total width. The Problem is the "startLocation does not have the correct width. I think its because its nested inside another element but I need the other element to have the class autocompleted so I don't know how to fix this.
Sorry If this is a stupid beginner question. Im new to html and bootstrap.
What is the "mb-3" class for in row?
Did you mean md-3? Which you would only need to set column widths (if you're using bootstrap).
Open the developer tools and check the padding and margin around the form. The form itself, and the nested div are probably taking up some space. Also the inputs have different parents so your styling might not be targeting the right selector.
I would like to display remember me checkbox and submit button inline using Bootstrap 3 inside my Login form.
<div class="row">
<div class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" value="1"> Remember me
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
They do not align vertically very well, especially on mobile size. I would like them to be vertically aligned so the checkbox is in the middle of Submit button.
Also Remember me label is not aligned nicely with checkbox, it seems like words Remember me are slightly higher than chekcbox.
How to solve this ?
What you could do is create another row class inside of the first one. Then inside of that create two classes of two, so col-x-6 twice. Inside one place the check box and inside the other place the button. Then use CSS to clean up and misalignment.
I don't know if this will solve the problem, but it may be worth a try!:)
Consider below html code, which uses bootstrap 3 input group to create an input three input groups.
<h1>border radius</h1>
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon">
<input value="false" type="radio"/>
</span>
<div class="input-group">
<span class="input-group-addon">*</span>
<input type="text" class="form-control"/>
<span class="input-group-addon">?</span>
</div>
</div>
</div>
The default bootstrap style puts border radius for all input groups, which is not good for the middle input groups (I mean the tiny left radius around * ).
To remove this radius, I try to set the border radius for all input groups to zero except the last one.
div.input-group > div.input-group > span.input-group-addon:not:last-child{
border-radius: 0px !important;
}
But it did not work !
Please let me know what is wrong with this selector, and if I can do it easier !
fiddle : http://jsfiddle.net/mtamx8bs/
:not() is a functional pseudo-class so it needs parentheses around its argument:
div.input-group > div.input-group > span.input-group-addon:not(:last-child)
And on that note I removed the !important as it's no longer needed now that I've fixed the selector.
Due to the way that Bootstrap applies the rounded border styling to the .input-group-addon class, only the first and last "addon" within an .input-group will end up with rounded corners.
Based on this, I'd suggest you consider wrapping all your required elements in a single input group, rather than trying to nest one inside the other.
For example:
<div class="input-group">
<span class="input-group-addon"><input value="false" type="radio"/></span>
<span class="input-group-addon">*</span>
<input type="text" class="form-control" />
<span class="input-group-addon">?</span>
</div>
I updated your fiddle with these changes if you want to play with it. (Edit: or check this one for a slightly more verbose version, showing how much cleaner the code looks with multiple groups)
As an extra note: there are some cases where you may end up nesting different types of "group" classes from Bootstrap, but you'll probably need to play with them to work out which combinations will achieve exactly what you want.
This page in the docs shows an example of two button elements (normal button and a drop-down button) inside an .input-group-btn class, which is nested inside an .input-group.
I'm developing a web site where users can search for customers. Part of the search allows them to filter by country, state or city. In order to balance flexibility for those on big devices and a neat UI for those on small devices, I've added four input controls, one each for country, state and region, all to be shown on big devices, and one combined control for location to be shown in small devices.
This is all using the standard stuff that comes when you start a new MVC project in Visual Studio 2013. The HTML looks like this...
<div class="form-inline form-group" id="filterGroup">
<span style="white-space: nowrap"><label for="namefilter">Name:</label> <input id="namefilter" type="text" class="form-control k-input k-textbox" /></span>
<span style="white-space: nowrap"><label for="locationfilter" class="visible-xs">Location:</label> <input id="locationfilter" type="text" class="form-control k-input k-textbox visible-xs" /></span>
<span style="white-space: nowrap"><label for="countryfilter" class="hidden-xs">Country:</label> <input id="countryfilter" type="text" class="form-control k-input k-textbox hidden-xs" /></span>
<span style="white-space: nowrap"><label for="regionfilter" class="hidden-xs">State:</label> <input id="regionfilter" type="text" class="form-control k-input k-textbox hidden-xs" /></span>
<span style="white-space: nowrap"><label for="cityfilter" class="hidden-xs">City:</label> <input id="cityfilter" type="text" class="form-control k-input k-textbox hidden-xs" /></span>
<span style="white-space: nowrap"><button id="filterBtn" class="btn btn-primary btn-sm">Filter</button> <button id="clearBtn" class="btn btn-primary btn-sm">Clear</button></span>
</div>
Now when you view this on a big device, it looks fine...
(Note that the HTML appears inside the toolbar section of a KendoUI grid, but that's not relevant to the problem, as the issue is exactly the same if I place it directly in the body of the document)
However, if you view it on a small device (or just make the browser window narrow), it looks poor...
The location textbox is on a separate line from the label, which it shouldn't be, as they are both wrapped in a span with white-space set to nowrap, there is a large margin above the location textbox, and the two buttons are pushed down onto yet another line. All of this should fit on one line, but instead looks ugly and takes up far too much space.
Any ideas what I did wrong? I want the name and location controls on one line, preferably with the buttons as well.
If you want proper responsive layout using BootStrap3, you should use the 12-grid system.
In your form, use the <div class="row"> and <div class="col-md-2"> (or whatever size suits you) in order to properly format it.
More specific to forms, you have an example of a properly formatted one here http://getbootstrap.com/css/#forms-horizontal
More info here: http://getbootstrap.com/css/#grid
Multiple places in my code I need to position this element (a globe glyph) directly to the right of a textbox, almost touching it. You could do this by doing the following
<div class="col-md-3">
<input class="form-control" id="CustomTaskTitle" name="CustomTaskTitle" type="text" />
</div>
<div class="col-md-1">
<span class="glyphicon glyphicon-globe pull-left"></span>
</div>
but then you waste and entire column. Any solutions?
**You will have to expand the jFiddle output window to max size to get the row layout
Heres my JFiddle - http://jsfiddle.net/5Rhzh/
You'll notice the glyph automatically goes beneath the textbox because there is no room in the column.
Bootstrap already has this. Its a component called input groups.
The correct way to do it would be
<div class="col-md-3">
<div class="input-group">
<input class="form-control" id="CustomTaskTitle" name="CustomTaskTitle" type="text" >
<span class="glyphicon glyphicon-globe pull-left"></span>
</div>
</div>
And there you have space for another 3 columns