How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components
青灯夜游
Release: 2021-12-06 19:00:39
forward
2239 people have browsed it
How to use modal box in
Bootstrap? The following article will introduce to you the usage of the Modal component of the Bootstrap5 modal pop-up box. I hope it will be helpful to you!
1 How the Bootstrap5 modal pop-up box works
Use Bootstrap's JavaScript mode plug-in to add dialog boxes to the site for light boxes, user notifications, or Fully customizable content. [Related recommendations: "bootstrap Tutorial"]
The interactive window is built with HTML, CSS and JavaScript. They sit above any other content in the file and remove scrolling from the body so that the interactive viewport's content scrolls.
Clicking the "backdrop" of the interactive window will automatically close the interactive window.
Bootstrap only supports one interactive window at a time. Nested interactive windows are not supported because we consider nested interactive windows to be a poor user experience.
The interactive window uses position: fixed, which is a bit special in rendering and presentation. Place your interactive viewport HTML at the top level whenever possible to avoid potential interference from other elements. You may run into problems when adding a .modal inside another fixed element.
Because of position: fixed, there are some additional instructions for using interactive windows on mobile devices.
According to the way HTML5 defines semantics, the autofocus HTML attribute has no impact on Bootstrap interactive windows. To achieve the same effect, use some custom JavaScript: the autofocus HTML attribute
2 Full example
2.1 Full example
Toggle by clicking the button below Dynamic window rendering. It will slide down from the top of the page and fade in. Click the close button or click the background area to close the pop-up window.
模态框
确认提示
删除后不可恢复!
Copy after login
2.2 Static background
When the background is set to static, the interactive window will not be closed by clicking on the background. Just adddata-bs-backdrop="static" data-bs-keyboard="false"to
.
Replace the code
Copy after login
in the 26.2.1 example with
Copy after login
There is no difference in appearance. Just click on the background and the pop-up box will no longer be closed.
3 Scrolling long content
3.1 Using browser scroll bars
By default, when the user's dynamic windows become too long, their scrolling is independent of On the page itself, vertical scroll bars will be enabled on the browser.
比如Soul,这个推出不到5年的社交产品在年轻群体中迅速打开市场,Soul的DAU已达千万量级,同比增长94.4%,其中73.9%的DAU是Z世代。同时也凭借全新的社交玩法达成3300万MAU。更值得关注的是,从2020年7月开始至今,用户增长速度平均保持在105%以上。根据腾讯智库数据,Soul在95后的渗透率达到了行业前三,TGI指标维度(Target Group Index,用于衡量用户偏好度)上Soul在95后群体中达到了127,远超过100的平均值,足以反映Soul在95后群体中的受欢迎程度。
You can add modal-dialog-scrollable to modal-dialog to create a pop-up window with a scrollable body .
Replace
Copy after login
in the 26.3.1 example with
Copy after login
4 Vertically center
Addmodal-dialog-centeredtomodal-dialogto vertically center the interactive window. This setup is relatively simple, just make the following changes.
Copy after login
The bottom one is with a scroll bar
复制代码
Copy after login
The above example may not be visible because only part of the window is selected in the screenshot. The following two pictures are 26.2.1 Demonstration of the window. The display effect after raising the height, and the display effect after adding vertical centering.
5 Multiple modal box switching
Switch between multiple modalities and cleverly place data -bs-target and data-bs-Toggle attributes. For example, you can toggle password reset mode within an open login mode. Please note that multiple modals cannot be open at the same time. This method simply switches between two separate modalities.
The above is the detailed content of How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn