繁体   English   中英

您如何在页面上水平居中引导模式?

[英]How do you horizontally center a bootstrap modal on the page?

我试图让我的引导模式在页面出现后水平居中,但我似乎只能让代码垂直居中。 到目前为止,这是我的代码:

$(document).ready(function () {
            function alignModal() {
                var modalDialog = $(this).find(".modal-dialog");

                // Applying the top margin on modal dialog to align it vertically center
                modalDialog.css("margin-top", Math.max(0, ($(window).height() - modalDialog.height()) / 2));
            }
            // Align modal when it is displayed
            $(".modal").on("shown.bs.modal", alignModal);

            // Align modal when user resize the window
            $(window).on("resize", function () {
                $(".modal:visible").each(alignModal);
            });
        });

你的意思是垂直居中吗? 因为你写了两次“水平”。 如果垂直:来自Bootstrap 的文档页面

.modal-dialog-centered添加到 .modal-dialog 以垂直居中模式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM