Posted on

How can you make a Login button, and when clicking on it, a login page pops up? Using Bootstrap modal!

modal
Bootstrap Modal

There are 2 steps to go.

Firstly, implement the body of the form inside the modal

<div id="loginModal" class="modal fade" role="dialog">
        <div class="modal-dialog modal-lg" role="content">
            <!-- Model content-->
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Login</h4>
                    <button type="button" class="close"
                    data-dismiss="modal">×</button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-row">
                            <div class="form-group col-sm-4">
                                <label class="sr-only" for="exampleInputEmail3">Email address</label>
                                <input type="email" class="form-control form-control-sm mr-1" id="exampleInputEmail3" placeholder="Enter email">
                            </div>
                            <div class="form-group col-sm-4">
                                <label class="sr-only" for="exampleInputPassword3">Password</label>
                                <input type="password" class="form-control form-control-sm mr-1" id="exampleInputPassword3" placeholder="Password">
                            </div>
                            <div class="col-sm-auto">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox">
                                    <label class="form-check-label"> Remember me</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-row">
                            <button type="button" class="btn btn-secondary btn-sm ml-auto" data-dismiss="modal">Cancel</button>
                            <button type="submit" class="btn btn-primary btn-sm ml-1">Sign in </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

The second step is to add the button and link it to its content

<span class="navbar-text">
                <a data-toggle="modal" data-target="#loginModal" rel="noopener noreferrer">
                    <span class="fa fa-sign-in"></span>
                    Login
                </a>
            </span>

Leave a Reply

Your email address will not be published. Required fields are marked *