JSFiddle - React, Tailwind, and code Playground

Modal Form

by Jennifer Perrin

HTML

<p><a href="#myModal" role="button" data-toggle="modal">Login</a></p>

<!-- modal for login form starts -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
        
<h3 id="myModalLabel">Login</h3>

    </div>
    <div class="modal-body">
        <!--form starts-->
        <div class="row">
            <div class="span5">
                <form method="post" action=".">
                    <fieldset>
                        <p>
                            <label>Username</label>
                            <input name="name" type="text" placeholder="Username">
                        </p>
                        <p>
                            <label>Password</label>
                            <input name="password" type="password" placeholder="Password">
                        </p>
                        <p>
                            <input type="submit" value="Login" class="submit" />
                        </p>
                    </fieldset>
                </form>
                <div class="clearfix"></div>
                <p><a href="#">Forgot username / password?</a> | <a href="#">Login with Facebook</a>
                </p>
            </div>
        </div>
        <!--form starts-->
    </div>
</div>
<!--modal for login form ends -->

CSS

body { margin: 20px; }

a {
    color: #E74710;
    cursor: pointer;
    font-style: normal;
    outline: medium none;
    text-decoration: none;
    transition: all 0.3s ease 0s;
}
a:hover {
    color: #808080;
    text-decoration: none;
}

.modal-header h3 {
    line-height: 30px;
    margin: 0;
}
h3 {
    font-size: 16px;
}
h1, h2, h3, h4, h5, h6 {
    color: #343434;
    font-style: normal;
    font-weight: 600;
    line-height: 1.3em;
    margin-bottom: 15px;
}

.modal {
    left: 20px;
    margin: 0;
    position: fixed;
    right: 20px;
    top: 20px;
    width: auto;
}
.modal.fade.in {
    top: auto;
}
.modal {
    left: 10px;
    right: 10px;
    top: 10px;
}
.modal-header .close {
    margin: -10px;
    padding: 10px;
}
.modal-open .modal .dropdown-menu {
    z-index: 2050;
}
.modal-open .modal .dropdown.open {
}
.modal-open .modal .popover {
    z-index: 2060;
}
.modal-open .modal .tooltip {
    z-index: 2080;
}
.modal-backdrop {
    background-color: #000000;
    bottom: 0;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 1040;
}
.modal-backdrop.fade {
    opacity: 0;
}
.modal-backdrop, .modal-backdrop.fade.in {
    opacity: 0.8;
}
.modal {
    background-clip: padding-box;
    background-color: #FFFFFF;
    border: 1px solid rgba(0, 0, 0, 0.3);
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
    left: 50%;
    margin: -250px 0 0 -280px;
    overflow: auto;
    position: fixed;
    top: 50%;
    width: 560px;
    z-index: 1050;
}
.modal.fade {
    top: -25%;
    transition: opacity 0.3s linear 0s, top 0.3s ease-out 0s;
}
.modal.fade.in {
    top: 50%;
}
.modal-header {
    border-bottom: 1px solid #EEEEEE;
    padding: 9px 15px;
}
.modal-header .close {
    margin-top: 2px;
}
.modal-header h3 {
    line-height: 30px;
    margin: 0;
}
.modal-body {
    max-height: 400px;
    overflow-y: auto;
    padding: 15px;
}
.modal-form {
    margin-bottom: 0;
}
.modal-footer {
    background-color:...

JavaScript

!function ($) {
    "use strict";
    /* MODAL CLASS DEFINITION
     * ====================== */
    var Modal = function (element, options) {
        this.options = options
        this.$element = $(element)
            .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
        this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
    }
    Modal.prototype = {
        constructor: Modal,
        toggle: function () {
            return this[!this.isShown ? 'show' : 'hide']()
        },
        show: function () {
            var that = this,
                e = $.Event('show')
                this.$element.trigger(e)
                if (this.isShown || e.isDefaultPrevented()) return
                $('body').addClass('modal-open')
                this.isShown = true
                this.escape()
                this.backdrop(function () {
                    var transition = $.support.transition && that.$element.hasClass('fade')
                    if (!that.$element.parent().length) {
                        that.$element.appendTo(document.body) //don't move modals dom position
                    }
                    that.$element.show()
                    if (transition) {
                        that.$element[0].offsetWidth // force reflow
                    }
                    that.$element.addClass('in')
                        .attr('aria-hidden', false)
                        .focus()
                    that.enforceFocus()
                    transition ? that.$element.one($.support.transition.end, function () {
                        that.$element.trigger('shown')
                    }) : that.$element.trigger('shown')
                })
        },
        hide: function (e) {
            e && e.preventDefault()
            var that = this
            e = $.Event('hide')
            this.$element.trigger(e)
            if (!this.isShown || e.isDefaultPrevented()) return
           ...