IT業界のすみっこ暮らし

ふと気がついたときの記録

Bootstrap:Modal関連メモ(20170123)

モダルを真ん中に表示する

stackoverflow.com

CSS

/* Modal Settings Start (vertical position center) */
.vertical-alignment-helper {
    display:table;
    height: 100%;
    width: 100%;
    pointer-events:none; /* This makes sure that we can still click outside of the modal to close it */
    overflow:hidden;
}
.vertical-align-center {
    /* To center vertically */
    display: table-cell;
    vertical-align: middle;
    pointer-events:none;
}
.modal-content {
    /* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
    width:inherit;
    height:inherit;
    /* To center horizontally */
    margin: 0 auto;
    pointer-events: all;
    overflow:hidden;
}

HTML

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="vertical-alignment-helper">
        <div class="modal-dialog vertical-align-center">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>

                    </button>
                    <h4 class="modal-title" id="myModalLabel">Modal title</h4>

                </div>
                <div class="modal-body">...</div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
</div>

モダルのサイズを変更する

kishiken.com

Bootstrap正規

.modal-dialogを宣言しているdivにサイズ指定用のクラスを追加する。(.modal-sm / .modal-lg)

<div class="modal-dialog modal-lg">

カスタマイズ

<div class="modal-dialog" style="width:400px;">

OR

<div class="modal-content" style="width:400px;">