T2020 Jackson
T2020 Jackson

Reputation: 17

How to align your button to be on your right not left in bootstrap?

I really need some help with my ligning of my div(next to my label there should be@EditorFor(model=>model.CourseName) not below. The issue is my@Razor is below not next to my label. Here is my label;

<div class="row">
            <div class="col-xs-3">
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                    Start New Course
                </button>
            </div>
        </div>

        
        <!-- Modal -->
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Start New Course</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                        <div class="form-group row"></div>
                        <label for="CourseName" class="col-sm-2 col-form-label">CourseName:</label>
                        <div class="col-sm-8">@Html.EditorFor(model => model.CourseName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "CourseName" } })
                           
                        </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-primary">Create Course</button>
                        </div>
                    </div>
            </div>
        </div>

    </div>

Upvotes: 1

Views: 40

Answers (1)

Rado
Rado

Reputation: 749

You can use bootstrap classes to align it to the right.

Add ml-auto to the col-xs-3

or add justify-content-end to row:

In the example I have added ml-auto to the column.

<div class="row">
            <div class="col-xs-3 ml-auto">
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                    Start New Course
                </button>
            </div>
        </div>

        
        <!-- Modal -->
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Start New Course</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                        <div class="form-group row"></div>
                        <label for="CourseName" class="col-sm-2 col-form-label">CourseName:</label>
                        <div class="col-sm-8">@Html.EditorFor(model => model.CourseName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "CourseName" } })
                           
                        </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-primary">Create Course</button>
                        </div>
                    </div>
            </div>
        </div>

    </div>

Upvotes: 1

Related Questions