Center button under form in bootstrap - html

i have some problems with Bootstrap. i centered form and button by using span6 offset3 and don't know how to center button under this form right now. i tried with text-align: center but still it's more on the left.
<div class="container">
<div class="row">
<div class="span6 offset3">
<form>
<input class="input-xxlarge" type="text" placeholder="Email..">
<p style="line-height: 70px; text-align: center;"><button type="submit" class="btn">Confirm</button></p>
</form>
</div>
</div>
</div>

Remove that <p> tag and add the button inside a <div class="form-actions"> like this:
<div class="form-actions">
<button type="submit" class="btn">Confirm</button>
</div>
an then augment the CSS class with:
.form-actions {
margin: 0;
background-color: transparent;
text-align: center;
}
Here's a JS Bin demo: http://jsbin.com/ijozof/2
Look for form-actions at the Bootstrap doc here:
http://twitter.github.io/bootstrap/base-css.html#buttons

With Bootstrap 3, you can use the 'text-center' styling attribute.
<div class="col-md-3 text-center">
<button id="button" name="button" class="btn btn-primary">Press Me!</button>
</div>

If you're using Bootstrap 4, try this:
<div class="mx-auto text-center">
<button id="button" name="button" class="btn btn-primary">Press Me!</button>
</div>

Width:100% and text-align:center would work in my experience
<p style="display:block; line-height: 70px; width:100%; text-align:center; margin:0 auto;"><button type="submit" class="btn">Confirm</button></p>

Try adding this class
class="pager"
<p class="pager" style="line-height: 70px;">
<button type="submit" class="btn">Confirm</button>
</p>
I tried mine within a <div class=pager><button etc etc></div> which worked well
See http://getbootstrap.com/components/ look under Pagination -> Pager
This looks like the correct bootstrap class to center this, text-align: center; is meant for text not images and blocks etc.

I do it like this <center></center>
<div class="form-actions">
<center>
<button type="submit" class="submit btn btn-primary ">
Sign In <i class="icon-angle-right"></i>
</button>
</center>
</div>

You can use this
<button type="submit" class="btn btn-primary btn-block w-50 mx-auto">Search</button>
Look something like this
Complete Form code -
<form id="submit">
<input type="text" class="form-control mt-5" id="search-city"
placeholder="Search City">
<button type="submit" class="btn btn-primary mt-3 btn-sm btn-block w-50
mx-auto">Search</button>
</form>

Using Bootstrap, the correct way is to use the offset class. Use math to determine the left offset. Example: You want a button full width on mobile, but 1/3 width and centered on tablet, desktop, large desktop.
So out of 12 "bootstrap" columns, you're using 4 to offset, 4 for the button, then 4 is blank to the right.
See if that works!

With Bootstrap you can simply use class text-center:
<div class="container">
<div class="row">
<form>
<input class="input-xxlarge" type="text" placeholder="Email..">
</form>
<div class="text-center">
<button type="submit" class="btn">Confirm</button>
</div>
</div>
</div>
DEMO

Try giving default width, display it with block and center it with margin: 0 auto;
like this:
<p style="display:block; line-height: 70px; width:200px; margin:0 auto;"><button type="submit" class="btn">Confirm</button></p>

It's working completely try this:
<div class="button pull-left" style="padding-left:40%;" >

Related

How to fix CSS with placing multiple buttons on one side of a row in Bootstrap?

I am trying to make a simple example where I have a row and inside that row is columns. One column is for the name of the left-hand side and on the right-hand side is the three buttons that exist. However, I am having issues placing the buttons properly on the right side as well as spacing them at an appropriate distance. I tried using the max-width in my CSS but I just ended up screwing up the project even more. Below is my HTML/CSS file:
#submitGPBtn {
margin-right: 30px;
}
<div class="row">
<div>
<h4> Group Pattern Test</h4>
</div>
<div class="mx-auto">
<button class="btn btn-primary">Save</button>
</div>
<div class="mx-auto">
<button class="btn btn-primary">Close</button>
</div>
<div class="ml-auto">
<button class="btn btn-primary" id="submitGPBtn">Submit</button>
</div>
</div>
You would want to use a btn-toolbar to group your buttons in-line.
#submitGPBtn {
margin-right: 30px;
}
<div class="row">
<div class="col">
Group Pattern Test
</div>
<div class="col">
<div class="btn-toolbar">
<button class="btn btn-primary">Save</button>
<button class="btn btn-primary">Close</button>
<button class="btn btn-primary" id="submitGPBtn">Submit</button>
</div>
</div>
</div>
This question has been answered well here. But here's an example below, add float-right class to your button bar, you can put a breakpoint in the class like float-sm-right but float-right works on any viewport width.
#submitGPBtn {
margin-right: 30px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col">
Group Pattern Test
</div>
<div class="col">
<div class="btn-toolbar float-right">
<button class="btn btn-primary">Save</button>
<button class="btn btn-primary">Close</button>
<button class="btn btn-primary" id="submitGPBtn">Submit</button>
</div>
</div>
</div>
In bootstrap ml-auto is fine to align buttons to the right, but you should apply it only to the first item after the "offset".
I added ml-1 to space the other buttons and a lightyellow background just to show where the container ends.
My personal suggestion when you use bootstrap is to code inside a container, you can't set its size to what you want but it prevents stretching in wide monitors.
.container {
background-color: lightyellow;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col text-left">
<h4> Group Pattern Test</h4>
</div>
<button class="btn btn-success ml-auto">Save</button>
<button class="btn btn-success ml-1">Close</button>
<button class="btn btn-success ml-1" id="submitGPBtn">Submit</button>
</div>
</div>

MaterializeCSS: Buttons do not vertically align (but input-fields do) inside footer

If I use valign-wrapper with a .btn in a Materialize.css .page-footer, it does not vertically align. e.g., the following html:
<footer class="page-footer">
<div class="valign-wrapper row col 12" id="rowContainer">
<div class="col s12">
<button class="btn btn-block waves-effect waves-light light-blue" type="submit" name="action">btn1</button>
</div>
</footer>
produces:
Note: in my stylesheet, I have:
.btn-block
{
width: 100%;
}
To make buttons with the .btn-block class fit to the width of their container.
If I replace the button with an .input-field, everything works as expected (i.e. it is vertically aligned in the footer). e.g.:
<footer class="page-footer">
<div class="valign-wrapper row col 12" id="rowContainer">
<div class="input-field col s12">
<input placeholder="Input1" type="text" class="center-align">
</div>
</footer>
produces:
Why is this happening and how can I vertically align my button? It is my understanding that .valign-wrapper should do this for me.
Note that in my actual application, I am add several buttons to the footer; that is why I am using the .row class with a specified number of columns.
Okay I see. I've had issues vertically aligning certain things within divs in Materialize too. The work around can be tedious but try something like this.
HTML:
<footer class="page-footer">
<div class="valign-wrapper row col 12" id="rowContainer">
<div class="col s12">
<button class="btn btn-block waves-effect waves-light light-blue"
type="submit" name="action">btn1</button>
</div>
</footer>
CSS:
.valign-wrapper {
height:100px;
padding-top: 70px;
border-style: solid; /*just used to show footer height*/
border-color: black; /*just used to show footer height*/
}
.btn-block {
width: 100%;
}
You'll probably have to tweak the
padding-top: 70px;
line to fit your footer.
Here's the codepen:
https://codepen.io/controllz/pen/mdyLRXQ
I added the border in CSS just to show the footer height. Remove that when you get it right.
Hope this helps.
If I understand you correctly, you are trying to vertically align your buttons? You can add a line break after each instance within the footer.
<footer class="page-footer">
<div class="valign-wrapper row col 12" id="rowContainer">
<div class="col s12">
<button class="btn btn-block waves-effect waves-light light-blue"
type="submit" name="action">btn1</button>
<br>
<button class="btn btn-block waves-effect waves-light light-blue"
type="submit" name="action">btn1</button>
<br>
<button class="btn btn-block waves-effect waves-light light-blue"
type="submit" name="action">btn1</button>
</div>
</footer>

creating simple button to use the size of column from bootstrap

My idea is to create a simple green button. No text, no border, just a green shape, which would inherit the size of col-md-12 from bootstrap. I have seen there are many similar questions, however I have a problem with basic understanding so I would appreciate if you would help me understand it.
<body>
<div class="col-md-12">
<button class="button" type="button" style="border:none; display:inline-block; color:green;"></button>
</div>
</body>
So, this is what I did. I have a body and I have a col-md-12 class. This is ok I guess. Then I decided to create a button. I have a button tag, class=button, type=button and I have a style > simple green color and inline-block to display this button over col-md-12. However! Nothing happens. May I ask why?
I don't want to put any sizes for purpose, I want just to fit whole col-md-12. May I ask what I don't understand correctly? Thank you.
Just add a class 'form-control' to button tag.
JSFiddle
<div class="row">
<div class="col-md-12">
<button class="btn btn-success form-control" type="button">Hello</button>
</div>
</div>
As said by j08691, you have to embed your columns inside rows for it to work properly:
<body>
<div class="row">
<div class="col-md-12">
<button class="button" type="button" style="border:none; display:inline-block; color:green;"></button>
</div>
</div>
</body>
But this wont be enough, because by default your button will not take the whole space, so you need to add a width: 100%; property on it:
<body>
<div class="row">
<div class="col-md-12">
<button class="button" type="button" style="width: 100%; border:none; display:inline-block; color:green;"></button>
</div>
</div>
</body>
Demo: https://jsfiddle.net/w1njoLL0/
Add w-100 to the button's class, e.g.:
<div class="mt-5 row justify-content-center">
<div class="col-3">
<button id="continue-button" class="btn btn-primary btn-lg w-100">
Continue
</button>
</div>
</div>

Aligning elements in html using bootstrap classes

I have the following code
html page(part of it)
<div class="container">
<div class="right-page col-md-9">
<div class="row">
<div class="category-item col-md-4">
<form action="/settings/category/2/" method="post" class="form-inline">
<div class="container">
<div class="row input-container">
<div class="form-group">
<div class="col-md-8">
<input class="form-control input-sm col-md-3" type="text" value="KONS ">
</div>
<div class="col-md-3">
<input class="form-control input-sm col-md-3 myColorPicker">
</div>
</div>
</div>
</div>
<div class="container">
<div class="row btn-container">
<button class="btn btn-default btn-sm edit-category">Cancel</button>
<button name="delete" class="btn btn-default btn-sm">Delete</button><input type="submit" name="submit" class="btn btn-default btn-sm" value="Save">
</div>
</div>
</form>
</div>
</div>
</div>
and the css (part of it)
.diagnosis-phrase,
.treatment-phrase,
.category-item{
padding-bottom: 1em;
padding-top: 0.5em;
border: 1px solid black;
margin-bottom: 0.5em;
}
.diagnosis-phrase input[type="text"],
.treatment-phrase input[type="text"],
.category-item input[type="text"]{
margin-bottom:0.5em;
}
.category-item p{
padding-left: 0.5em;
padding-bottom:0.3em;
border-radius:0.5em;
width:50%;
}
The bootply for it. The part of html is the right column of a two column webpage. As you can see inside the div with black border I have two input boxes(For some reason the second appears outside the div with borders but in my working code appears correctly. Maybe because of me providing part of page.). My problem is that the first one is not aligned with the Cancel button. How can I do that using bootstrap classes?
if you use the following styles
.form-group .col-md-8:first-child {padding-left:0;}
It should fix your problem
Or if you just change the col-md-8 class on your div to col-md-pull-8 it should also achieve the same thing

How to center buttons in Twitter Bootstrap 3?

I am building a form in Twitter Bootstrap but I'm having issues with centering the button below the input in the form. I have already tried applying the center-block class to the button but that didn't work. How should I fix this?
Here is my code.
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="singlebutton"></label>
<div class="col-md-4">
<button id="singlebutton" name="singlebutton" class="btn btn-primary center-block">
Next Step!
</button>
</div>
</div>
Wrap the Button in div with "text-center" class.
Just change this:
<!-- wrong -->
<div class="col-md-4 center-block">
<button id="singlebutton" name="singlebutton" class="btn btn-primary center-block">Next Step!</button>
</div>
To this:
<!-- correct -->
<div class="col-md-4 text-center">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Next Step!</button>
</div>
Edit
As of BootstrapV4, center-block was dropped #19102 in favor of m-*-auto
According to the Twitter Bootstrap documentation: http://getbootstrap.com/css/#helper-classes-center
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="singlebutton"></label>
<div class="col-md-4 center-block">
<button id="singlebutton" name="singlebutton" class="btn btn-primary center-block">
Next Step!
</button>
</div>
</div>
All the class center-block does is to tell the element to have a margin of 0 auto, the auto being the left/right margins. However, unless the class text-center or css text-align:center; is set on the parent, the element does not know the point to work out this auto calculation from so will not center itself as anticipated.
See an example of the code above here: https://jsfiddle.net/Seany84/2j9pxt1z/
<div class="row">
<div class="col-sm-12">
<div class="text-center">
<button class="btn btn-primary" id="singlebutton"> Next Step!</button>
</div>
</div>
</div>
add to your style:
display: table;
margin: 0 auto;
<div class="container-fluid">
<div class="col-sm-12 text-center">
<button class="btn btn-primary" title="Submit"></button>
<button class="btn btn-warning" title="Cancel"></button>
</div>
</div>
You can do it by giving margin or by positioning those elements absolutely.
For example
.button{
margin:0px auto; //it will center them
}
0px will be from top and bottom and auto will be from left and right.
I tried the following code and it worked for me.
<button class="btn btn-default center-block" type="submit">Button</button>
The button control is in a div and using center-block class of bootstrap helped me to align the button to the center of div
Check the link where you will find the center-block class
http://getbootstrap.com/css/#helper-classes-center
use text-align: center css property
Update for Bootstrap 4:
Wrap the button with a div set with the 'd-flex' and 'justify-content-center' utility classes to take advantage of flexbox.
<!-- Button -->
<div class="form-group">
<div class="d-flex justify-content-center">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">
Next Step!
</button>
</div>
</div>
The benefit of using flexbox is being able to add additional elements/buttons on the same axis, but with their own separate alignment. It also opens up the possibility of vertical alignment with the 'align-items-start/center/end' classes, too.
You could wrap the label and button with another div to keep them aligned with each other.
e.g. https://codepen.io/anon/pen/BJoeRY?editors=1000
You can do the following. It also avoids buttons overlapping.
<div class="center-block" style="max-width:400px">
Accept
Reject
</div>
It works for me
try to make an independent <div>then put the button into that.
just like this :
<div id="contactBtn">
<button type="submit" class="btn btn-primary ">Send</button>
</div>
Then Go to to your CSSStyle page and do the Text-align:center like this :
#contactBtn{text-align: center;}
For Bootstrap 3
we divide the space with the columns, we use 8 small columns (col-xs-8), we leave 4 empty columns (col-xs-offset-4) and we apply the property (center-block)
<!--Footer-->
<div class="modal-footer">
<div class="col-xs-8 col-xs-offset-4 center-block">
<button type="submit" class="btn btn-primary">Enviar</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
For Bootstrap 4
We use Spacing, Bootstrap includes a wide range of abbreviated and padded response margin utility classes to modify the appearance of an element.
The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.
more info here: https://getbootstrap.com/docs/4.1/utilities/spacing/
<!--Footer-->
<div class="modal-footer">
<button type="submit" class="btn btn-primary ml-auto">Enviar</button>
<button type="button" class="btn btn-danger mr-auto" data-dismiss="modal">Cerrar</button>
</div>
I had this problem. I used
<div class = "col-xs-8 text-center">
On my div containing a few h3 lines, a couple h4 lines and a Bootstrap button.
Everything besides the button jumped to the center after I used text-center so I went into my CSS sheet overriding Bootstrap and gave the button a
margin: auto;
which seems to have solved the problem.
or you can give specific offsets to make button position where you want simply with bootstrap grid system,
<div class="col-md-offset-4 col-md-2 col-md-offset-5">
<input type="submit" class="btn btn-block" value="submit"/>
this way, also let you specify button size if you set btn-block.
sure, this will only work md size range, if you want to set other sizes too, use xs,sm,lg.