


How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components
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.
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="../bootstrap5/bootstrap.min.css" rel="stylesheet"> <title>模态框</title> </head> <body> <div> <!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal"> 删除内容 </button> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div> <div> <div> <h5 id="确认提示">确认提示</h5> <button type="button" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div> 删除后不可恢复! </div> <div> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button> <button type="button" class="btn btn-primary">继续删除</button> </div> </div> </div> </div> </div> <script src="../bootstrap5/bootstrap.bundle.min.js" ></script> </body> </html>
2.2 Static background
When the background is set to static, the interactive window will not be closed by clicking on the background. Just add data-bs-backdrop="static" data-bs-keyboard="false"
to <div class="modal fade">. <p>Replace the code </p><pre class='brush:php;toolbar:false;'> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"></pre><p> in the 26.2.1 example with </p><pre class='brush:php;toolbar:false;'><div class="modal fade" id="exampleModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"></pre><p> There is no difference in appearance. Just click on the background and the pop-up box will no longer be closed. </p>
<h1 id="Scrolling-long-content">3 Scrolling long content</h1>
<h2 id="Using-browser-scroll-bars">3.1 Using browser scroll bars</h2>
<p>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. </p><pre class='brush:php;toolbar:false;'><!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="">
<meta name="description" content="">
<link href="../bootstrap5/bootstrap.min.css" rel="stylesheet">
<title>模态框</title>
</head>
<body>
<div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModalLong">
滚动弹窗演示
</button>
<div class="modal fade" id="exampleModalLong" tabindex="-1" aria-labelledby="exampleModalLongTitle"
aria-hidden="true">
<div>
<div>
<div>
<h5 id="万不看脸社交的年轻人">3300万不看脸社交的年轻人</h5>
<button type="button" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div>
<p>Z世代正在成为全球消费的生力军。这批出生于1995-2009年间的移动互联网原住民,在经济快速增长、多元文化碰撞、信息资讯空前繁盛的世界中,形成了既包容又挑剔的审美倾向,他们将个人兴趣与好恶作为社交的基础原则,进而导致新一代社交的“部落化”与“孤岛化”趋势。</p>
<p>这种由Z世代主导的全新数字行为方式,正在大张旗鼓地改造全球移动应用的形态,给沉寂已久的移动社交应用生态带来新的可能性。</p>
<p>长久以来,微信稳坐“社交霸主”地位的核心原因,是在于它巧妙地将熟人社会生态搬到线上并实现推广,换言之,微信解决的是生存问题。但当下年轻人有着更复杂的陪伴、表达与个人认同需求,需要寻求其它途径实现,这种需求反映到社交市场后,带来了新一代社交产品的个性化。</p>
<p>比如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后群体中的受欢迎程度。</p>
<p>Soul的成长路径,不依赖于既有关系链的转移或映射,也没有通过KOL或头部主播吸粉,而是平台完成冷启动,这种形态在海内外都找不到可对标的先例。这个年轻的社交平台是如何长成的?没有引入线下关系,Soul如何确保留存率和活跃度?</p>
<p>“反传统”的运营策略</p>
<p>纵观全球社交行业,从关系链闭环的⻆度来看,社交产品类型主要有三种。</p>
<p>第一种是把已有的外部关系链复制到社交产品中,主要是手机通讯录、邮箱等线下关系的映射,Facebook、微信、QQ都属于此类;第二种是基于地理位置进行匹配,比如“附近的人”、“同城交友”,上一代陌生人社交产品主要沿用这一路径;第三种是通过话题、内容或兴趣进行聚合,比如前段时间爆火的Clubhouse。</p>
<p>但Soul不属于上述任何一种。用户首次进入Soul时,要先打造一个全新身份、进行“灵魂测试”、最后打上个性化标签;基于这个虚拟的线上形象,用户可以进行自我表达、认知他人、探索世界、交流兴趣和观点、获得情感支持和认同感、从交流中获取信息和有质量的新关系。</p>
</div>
<div>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<script src="../bootstrap5/bootstrap.bundle.min.js" ></script>
</body>
</html></pre><p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/image/628/760/493/1638788219753440.png?x-oss-process=image/resize,p_40" class="lazy" title="163878823469018How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components" alt="How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components"></p>
<h2 id="Use-the-pop-up-scroll-bar">3.2 Use the pop-up scroll bar</h2>
<p>You can add modal-dialog-scrollable to modal-dialog to create a pop-up window with a scrollable body . </p>
<p>Replace </p><pre class='brush:php;toolbar:false;'><div class="modal-dialog"></pre><p> in the 26.3.1 example with </p><pre class='brush:php;toolbar:false;'><div class="modal-dialog modal-dialog-scrollable"></pre><p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/image/628/760/493/1638788219753440.png?x-oss-process=image/resize,p_40" class="lazy" title="163878823834615How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components" alt="How to use modal boxes in Bootstrap? A brief analysis of the usage of Modal components"></p>
<h1 id="Vertically-center">4 Vertically center </h1>
<p>Add <code> modal-dialog-centered
to modal-dialog
to vertically center the interactive window.
This setup is relatively simple, just make the following changes.
<div class="modal-dialog modal-dialog-centered">
The bottom one is with a scroll bar
复制代码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.
For more knowledge about bootstrap, please visit: bootstrap basic tutorial! !
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 main purpose of Bootstrap is to help developers quickly build responsive, mobile-first websites. Its core functions include: 1. Responsive design, which realizes layout adjustments of different devices through a grid system; 2. Predefined components, such as navigation bars and modal boxes, ensure aesthetics and cross-browser compatibility; 3. Support customization and extensions, and use Sass variables and mixins to adjust styles.

Bootstrap is better than TailwindCSS, Foundation, and Bulma because it is easy to use and quickly develop responsive websites. 1.Bootstrap provides a rich library of predefined styles and components. 2. Its CSS and JavaScript libraries support responsive design and interactive functions. 3. Suitable for rapid development, but custom styles may be more complicated.

Integrating Bootstrap in React projects can be done in two ways: 1) introduced using CDN, suitable for small projects or rapid prototyping; 2) installation using npm package manager, suitable for scenarios that require deep customization. With these methods, you can quickly build beautiful and responsive user interfaces in React.

Advantages of integrating Bootstrap into React projects include: 1) rapid development, 2) consistency and maintainability, and 3) responsive design. By directly introducing CSS files or using the React-Bootstrap library, you can use Bootstrap's components and styles efficiently in your React project.

Bootstrap is a framework developed by Twitter to help quickly build responsive, mobile-first websites and applications. 1. Ease of use and rich component libraries make development faster. 2. The huge community provides support and solutions. 3. Introduce and use class names to control styles through CDN, such as creating responsive grids. 4. Customizable styles and extension components. 5. Advantages include rapid development and responsive design, while disadvantages are style consistency and learning curve.

Bootstrapisafree,open-sourceCSSframeworkthatsimplifiesresponsiveandmobile-firstwebsitedevelopment.Itofferspre-styledcomponentsandagridsystem,streamliningthecreationofaestheticallypleasingandfunctionalwebdesigns.

What makes web design easier is Bootstrap? Its preset components, responsive design and rich community support. 1) Preset component libraries and styles allow developers to avoid writing complex CSS code; 2) Built-in grid system simplifies the creation of responsive layouts; 3) Community support provides rich resources and solutions.

Bootstrap accelerates web development, and by providing predefined styles and components, developers can quickly build responsive websites. 1) It shortens development time, such as completing the basic layout within a few days in the project. 2) Through Sass variables and mixins, Bootstrap allows custom styles to meet specific needs. 3) Using the CDN version can optimize performance and improve loading speed.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)