简体   繁体   English

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

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

I am trying to get my bootstrap modal to center horizontally on the page after it has appeared, but I can only seem to get the code to center it vertically.我试图让我的引导模式在页面出现后水平居中,但我似乎只能让代码垂直居中。 Here is my code so far:到目前为止,这是我的代码:

$(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);
            });
        });

Do you mean center vertically ?你的意思是垂直居中吗? Because you wrote "horizontally" twice.因为你写了两次“水平”。 If vertically: From Bootstrap's documentation page :如果垂直:来自Bootstrap 的文档页面

Add .modal-dialog-centered to.modal-dialog to vertically center the modal..modal-dialog-centered添加到 .modal-dialog 以垂直居中模式。

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

相关问题 您如何使用“位置:绝对”水平居中元素? - How do you horizontally center an element with “position: absolute”? 如何在引导程序模式的垂直顶部和水平中心显示图像加载器以及消息? - How to display image-loader along with message at vertically top and horizontally center of bootstrap modal? 如何使引导模态垂直居中? - How to vertically center the bootstrap modal? 将引导程序按钮水平居中 - Center the bootstrap buttons horizontally 如何让 Bootstrap 将内容居中,以便项目保持水平紧凑? - How do I get Bootstrap to center content so items stay horizontally compact? 您如何看待引导模式触发器的相应回调? - How do you think about respective callback for bootstrap modal triggers? 如何通过单击第一页中的按钮激活 Bootstrap 4 模态,将您重定向到激活模态的第二页? - How to activate Bootstrap 4 modal by clicking a button in the first page, that redirects you to a second page with modal activated? 你如何在引导模式中刷新内容? - How do you go about refreshing content inside a bootstrap modal? 如何将循环值传递给Bootstrap模式? - How do you pass looping values to a Bootstrap modal? 如何为Bootstrap模式窗口指定主要和辅助操作? - How do you specify the primary and secondary actions for a Bootstrap modal window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM