How to set an button align-right with Bootstrap?

CssTwitter Bootstrap

Css Problem Overview


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>

Css Solutions


Solution 1 - Css

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>

Solution 2 - Css

This worked for me:

<div class="text-right">
    <button type="button">Button 1</button>
    <button type="button">Button 2</button>
</div>

Solution 3 - Css

Try this:

<div class="row">
<div class="alert alert-info" style="min-height:100px;">
    <div class="col-xs-9">
        <a href="#" class="alert-link">Summary:Its some
           description.......testtesttest</a>  
    </div>
    <div class="col-xs-3">
        <button type="button" class="btn btn-primary btn-lg">Large      button</button>
    </div>
 </div>
</div>

Demo:

http://jsfiddle.net/Hx6Sx/1/

Solution 4 - Css

On bootstrap 4, you can do this add pull-right to your classname:

<div class="container">
	<div class="btn-block pull-right">
		<a href="#" class="btn btn-primary pull-right">Search</a>
		<a href="#" class="btn btn-primary pull-right">Apple</a>
		<a href="#" class="btn btn-primary pull-right">Sony</a>
	</div>
</div>

Solution 5 - Css

This work for me in bootstrap 4:

    <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 float-right">Large button</button>
    </div>

Solution 6 - Css

You can use the class name float-right:

function Continue({show, onContinue}) {
  return(<div className="row continue">
  { show ? <div className="col-11">
    <button class="btn btn-primary btn-lg float-right" onClick= {onContinue}>Continue</button>
    </div>
    : null }
  </div>);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2837851View Question on Stackoverflow
Solution 1 - CssGabriel C. TroiaView Answer on Stackoverflow
Solution 2 - CssLoichView Answer on Stackoverflow
Solution 3 - CssAnamView Answer on Stackoverflow
Solution 4 - CssAnuruddha ThennakoonView Answer on Stackoverflow
Solution 5 - CssMarcos Randulfe GarridoView Answer on Stackoverflow
Solution 6 - CssVivek RamasamyView Answer on Stackoverflow