Q:

How to Get Right Aligned Buttons in Bootstrap

0

How to Get Right Aligned Buttons in Bootstrap

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the text-right Class

You can simply use the class .text-right on the containing element to right align your Bootstrap buttons within a block box or grid column. It will work in both Bootstrap 3 and 4 versions.

Let's try out the following example to understand how it basically works:

<div class="container">
    <div class="row">
        <div class="col-md-12 bg-light text-right">
            <button type="button" class="btn btn-primary">Cancel</button>
            <button type="button" class="btn btn-warning">Save</button>
        </div>
    </div>
</div>

Let's check out one more example. Here, buttons and text are placed inside a div element side by side. To align text to the left and buttons to right we need to use the .float-right property on the button elements. Also, if the button elements are not inside a grid column (i.e., .col-*) then you also need apply the class .clearfix on the parent <div> element.

<div class="bg-light clearfix">
    <span>Click any button to proceed</span>    
    <button type="button" class="btn btn-warning float-right">Save</button>
    <button type="button" class="btn btn-primary float-right">Cancel</button>
</div>

If you're using the Bootstrap 3 version please replace the class float-right with pull-right class.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now