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>
According to the Twitter Bootstrap documentation: http://getbootstrap.com/css/#helper-classes-center
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/
You can do the following. It also avoids buttons overlapping.
Wrap the Button in div with "text-center" class.
Just change this:
To this:
Edit
As of BootstrapV4,
center-block
was dropped #19102 in favor ofm-*-auto
add to your style:
display: table; margin: 0 auto;
use
text-align: center
css property