Bootstrap: How to place button next to input-group - html

I can't work out (conforming to "proper bootstrap") how to get a button to sit next to an input-group within a div.
They need to be center aligned.
This is what I want it to look like...
This is what is happening...
Here is my current code.
<div>
<div>
<button type="button" class="btn">Delete</button>
</div>
<div>
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
</div>
I have created this js fiddle...
https://jsfiddle.net/ptwbn2av/
Thanks!

You could also try the pull-left class.
The classes .pull-left and .pull-right also exist and were previously
used as part of the media component, but are deprecated for that use
as of v3.3.0. They are approximately equivalent to .media-left and
.media-right, except that .media-right should be placed after the
.media-body in the html.
The html:
<div>
<div class="pull-left">
<button type="button" class="btn">Delete</button>
</div>
<div>
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
</div>
You can use:
style="margin-right:5px"
to add some spacing after the div, and then the new mark-up would be as follows:
<div>
<div class="pull-left" style="margin-right:5px">
<button type="button" class="btn">Delete</button>
</div>
<div>
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
</div>

With your current code, you can use the flexbox.
A powerful CSS layout module that gives us an efficient and simple way to lay out and align things.
<div class="flex">
<div>
<button type="button" class="btn">Delete</button>
</div>
<div>
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
</div>
.flex {
display: flex;
flex-direction: row;
}
This is the screenshot of the result:
You can learn more about flexbox here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Cheers!

divs are block elements, which means that they align vertically. For example,
<div>
Hello World!
</div>
<div>
Goodbye World!
</div>
would result in:
Hello World!
Goodbye World!
So, in order to make the elements flow horizontally, you have to make the div inline because inline elements can flow horizontally, such as text and <span>.
You can add a rule to your css:
#delete-button {
display:inline-block;
}
And of course, you should add an id attribute to the button.
If the above doesn't work, you should consider putting all the elements in one div because <button>, <input>, and <span> are all inline elements.

Just add the grid classes. Try this
<div>
<div class="col-xs-2">
<button type="button" class="btn">Delete</button>
</div>
<div class="col-xs-10">
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
</div>
https://jsfiddle.net/xbu9qtje/

Here one solution to the problem.
<div class="container">
<div class="input-group">
<button class="btn btn-outline-primary border-left-0 border" type="button">
Delete
</button>
<input type="text" class="form-control py-2" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
You can see the output at this link: codeply.com/p/xijLBe2vff.

Try the form-inline class in the root div, it will default to "inline" putting your fields one next to the other:
<div class="form-inline my-2 my-lg-0">
<button type="button" class="btn">Delete</button>
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>

you can just put
#Html.EditorFor(model => model.Name, new { htmlAttributes = new { #disabled = "true", #class = "input-group-addon", #style = "width:50px;text-align:center;" } })

<div class="col-md-12">
<div class="col-md-1">
<button type="button" class="btn">Delete</button>
</div>
<div class="col-md-11">
<div class="input-group">
<input type="text" class="form-control" value="1" />
<span class="input-group-addon">Update</span>
</div>
</div>
</div>

Related

Input gets messed up inside <details> tag

I am putting an input group inside a <details> tag. Outside, it works nicely, but inside, the input's height increases. Please note, I am using Halfmoon for my project. (Disclaimer: I built the project myself)
Anyway, here is the code:
<link href="https://cdn.jsdelivr.net/gh/halfmoonui/halfmoon#1.0.3/css/halfmoon.css" rel="stylesheet"/>
<div class="content">
<!-- Input group outside -->
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Shop</span>
</div>
<input type="text" class="form-control" placeholder="Enter products">
<div class="input-group-append">
<button class="btn btn-primary" type="button">Search</button>
</div>
</div>
<br />
<details open>
<summary>Click to open/close</summary>
This is the details for the summary.
<!-- Input group inside -->
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Shop</span>
</div>
<input type="text" class="form-control" placeholder="Enter products">
<div class="input-group-append">
<button class="btn btn-primary" type="button">Search</button>
</div>
</div>
</details>
</div>
As you can see, the input group on the inside of the <details> has a messed up height which also affects the text before it. Exactly what am I doing wrong here? For reference, the input group code is taken from the docs, specifically this example: https://www.gethalfmoon.com/docs/input-group/#stacking-text-and-buttons.
Thanks for any help.
Just add box-sizing: border-box to .input-group
.input-group {
box-sizing:border-box;
}
<link href="https://cdn.jsdelivr.net/gh/halfmoonui/halfmoon#1.0.3/css/halfmoon.css" rel="stylesheet"/>
<div class="content">
<!-- Input group outside -->
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Shop</span>
</div>
<input type="text" class="form-control" placeholder="Enter products">
<div class="input-group-append">
<button class="btn btn-primary" type="button">Search</button>
</div>
</div>
<br />
<details open>
<summary>Click to open/close</summary>
This is the details for the summary.
<!-- Input group inside -->
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Shop</span>
</div>
<input type="text" class="form-control" placeholder="Enter products">
<div class="input-group-append">
<button class="btn btn-primary" type="button">Search</button>
</div>
</div>
</details>
</div>

what is wrong with my code?

<div class="row">
<div class="container">
<div class="col-md-4 col-md-offset-4">
<div class="login-wrapper">
<div class="login-head">
<h3 class="text-center"> Log in </h3>
</div>
<form>
<div class="form-group">
<label for="email" class="sr-only"> Email </label>
<input type="text" placeholder="email here" class="form-control">
</div>
<div class="form-group">
<label for="email" class="sr-only"> Password </label>
<input type="text" placeholder="Password here" class="form-control">
</div>
<button type="button" class="btn btn-danger center-block"> Login </button>
</form>
</div>
</div>
</div>
</div>
After this code i got scroll bar in my browser so i inspect and found that if i make change
.row { margin-right: 0;}
it is just fine. It is nothing to do with my css i removed my css and tried. so should i change the value of .row all the time which is provided by bootstrap? default value is
.row{margin-right: -15px;}
EDIT: Code is formatted like code now
As mentioned in Bootstrap docs, container should be a top level wrapping class, which should contain class row. You've swapped these classes. I think this is the reason of issue.
First rule of bootstrap introduction says:
Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding.
Code should look:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-wrapper">
<div class="login-head">
<h3 class="text-center"> Log in </h3>
</div>
<form>
<div class="form-group">
<label for="email" class="sr-only"> Email </label>
<input type="text" placeholder="email here" class="form-control">
</div>
<div class="form-group">
<label for="email" class="sr-only"> Password </label>
<input type="text" placeholder="Password here" class="form-control">
</div>
<button type="button" class="btn btn-danger center-block"> Login </button>
</form>
</div>
</div>
</div>
</div>

Bootstrap input group button keeps wrapping to 2nd line in a modal

For some reason.. the button in the input-group keeps wrapping to the 2nd line.. the only way I can force it to stay on the 1st line is to use CSS to make the width 80% for example. But then the spacing seems off between the 4 elements..
Is there a cleaner way of doing this? I dont even know why it's wrapping to the 2nd line.. maybe because I'm using this in a Modal?
EDIT: how it looks like http://imgur.com/sfWqATl
<!--3rd row-->
<div class="row form-group">
<div class="col-md-2">
stuff...
</div>
<div class="col-md-4">
<div class="input-group">
<small>Logo 1 ID / File Path</small>
<br />
<div>
<input type="file" data-file="headline.contents.logo1path" id="logoPath1" class="hidden" />
<input type="text" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default glyphicon glyphicon-folder-open" type="button"></button>
</span>
</div>
</div>
</div>
<div class="col-md-4">
stuff...
</div>
<div class="col-md-2">
stuff...
</div>
</div>
I think you may have gotten a little mixed up in setting up the classes and elements to chain correctly based on the documentation. I re-wrote some of the code to model it from the bootstrap website, and it appears to work fine:
<div class="col-md-4">
<small>Logo 1 ID / File Path</small>
<input type="file" data-file="headline.contents.logo1path" id="logoPath1" class="hidden" />
<div class="input-group">
<input type="text" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i class="glyphicon glyphicon-folder-open"></i></button>
</span>
</div>
</div>
You can see the example here: http://www.bootply.com/EHvB2rn9YW

How to horizontally centre form in span with bootstrap 2.3.2?

I have the following code...
<div class="row">
<div class="span6">
<h2>Some Text</h2>
</div>
<div class="span6">
<form class="form-inline pull-right">
<input type="text" class="input-large">
<button type="submit" class="btn">Search</button>
</form>
</div>
</div>
...but the search form doesn't align with the h2 tag. Do I need to have the form custom styled via css or am I missing out on some default Bootstrap class to fix this?
Thanks so much for taking time to read/answer this query.
[edit]
http://jsfiddle.net/nuB23/
Added jsfiddle
Try to add this style:
[class*="span"], h2 {
display: inline;
}
Updated Fiddle
Remove the pull-right class on the form.
The other issue is the h2 has extra padding and is a block level. I think what you are really after is this:
<div class="nav"> </div>
<div class="container">
<form class="form-horizontal ">
<div class="control-group ">
<label class="control-label large" for="searchInput">Label text:</label>
<div class="controls search">
<div class="input-prepend "> <span class="add-on"><i class="icon-search"></i></span>
<input type="text" id="searchInput" />
<button type="submit" class="btn btn-primary">Search</button>
</div>
</div>
</div>
</form>
</div>
http://jsfiddle.net/dbrin/AV654/

How to prevent break in div with float right? (bootstrap)

I have the following HTML. And the text (tidbit) on the right keeps dropping off to the next line. This is in chrome. Is there a way to keep what is inside of the pull-right div together in one line? here is the jsFiddle.
<div class="container" style="width:500px;>
<div class="controls controls-row">
<span class="add-on">This can be quite long</span>
<div class="pull-right">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
<div style="text-align:right; width:40px;">tidbit</div>
</div>
</div>
</diV>
You can do this with two corrections:
Set display: inline-block in the "tidbit" div.
Set white-space: nowrap to the pull-right container.
<div class="container" style="width:500px;>
<div class="controls controls-row">
<span class="add-on">This can be quite long</span>
<div class="pull-right">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
<div style="text-align:right; width:40px; display: inline-block;">tidbit</div>
</div>
</div>
</diV>
.pull-right{
white-space:nowrap;
}
Example Fiddle
You can perhaps add pull-left and pull-right inside the pull-right parent container
<div class="container" style="width:500px;">
<div class="controls controls-row"> <span class="add-on">This can be quite long</span>
<div class="pull-right">
<div class="pull-left">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
</div>
<div class="pull-right" style="text-align:right; width:40px;">tidbit</div>
</div>
</div>
</diV>
Demo here
Hope this helps
Remove the div tag around tidbit and, if necessary, wrap the tidbit in a span - JSfiddle
<div class="container" style="width:500px;>
<div class="controls controls-row">
<span class="add-on">This can be quite long</span>
<div class="pull-right">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
<span>tidbit</span><!--Move this the before or after the button-->
</div>
</div>
</diV>
What is the combined width of div class pullright controls. It is exceeding 500px i think.
If width of these 3 exceeds 500px, tidbit text will move to next line. So control width