Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an button align-right with Bootstrap?

I am learning Bootstrap. The structure is a container within some context. At the bottom of the container, I put a button next to an description.

Now, I want to set the button align to the right without break the bootstrap structure. What should I do? I had set the "float:right" to the button style, but it appeared bad. The button is outside the "alert-info" background and not vertical align. Any better method?

<div class="alert alert-info"> <a href="#" class="alert-link">Summary:Its some description.......testtesttest</a>   <button type="button" class="btn btn-primary btn-lg" style="float:right;">Large      button</button>  </div> 
like image 217
user2837851 Avatar asked Dec 09 '13 02:12

user2837851


People also ask

How do you align a button to the right?

If you want to move the button to the right, you can also place the button within a <div> element and add the text-align property with its "right" value to the "align-right" class of the <div>.

How do I center align a button in Bootstrap?

Answer: Use the text-center Class You can simply use the built-in class . text-center on the wrapper element to center align buttons or other inline elements in Bootstrap. It will work in both Bootstrap 3 and 4 versions.


2 Answers

Bootstrap 5 implementation:

The class name is now "float-end" instead of "pull-right"

<div class="alert alert-info clearfix">     <a href="#" class="alert-link">       Summary:Its some description.......testtesttest     </a>      <button type="button" class="btn btn-primary btn-lg float-end">       Large button     </button> </div> 

Bootstrap 4 (and under) implementation:

Just add a simple pull-right class to the button, and make sure the container div is clearfixed:

<div class="alert alert-info clearfix">     <a href="#" class="alert-link">       Summary:Its some description.......testtesttest     </a>      <button type="button" class="btn btn-primary btn-lg pull-right">       Large button     </button> </div> 
like image 134
Gabriel C. Troia Avatar answered Oct 05 '22 01:10

Gabriel C. Troia


This worked for me:

<div class="text-right">     <button type="button">Button 1</button>     <button type="button">Button 2</button> </div> 
like image 39
Loich Avatar answered Oct 05 '22 01:10

Loich