Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to center the Bootstrap mode vertically

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to align the Bootstrap mode vertically, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

Answer: use the CSSmargin-top attribute

By default, the Bootstrap modal window is aligned with the top of the page, leaving some white space. But you can use a simple JavaScript technique to align it vertically in the middle of the page, as described in the following example. This solution dynamically adjusts the alignment of the mode, keeping it in the center of the page even if the user resizes the browser window.

Try this code for example »

Vertical Center Alignment of Bootstrap Modal Dialog

$(document) .ready (function () {

Function alignModal () {

Var modalDialog = $(this) .find (".modal-dialog")

/ / Applying the top margin on modal 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)

});

});

Launch Demo Modal

Confirmation

×

Do you want to save changes you made to document before closing?

If you don't save, your changes will be lost.

Close

Save changes

The above is all the contents of the article "how to align Bootstrap modes vertically". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report