Bootstrap 5 Modal
- Previous page BS5 carousel
- Next page Babban kwamiti na nuna kwanan
Modال
Modal تہاریف یرگای / یرگای تہاریف، یاندا صفییئنو تہاریف:
如何创建模态
下例展示如何创建基本模态:
Sample
<!-- 打开模态的按钮 --> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal"> Open modal </button> <!-- 模态 --> <div class="modal" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <!-- 模态标题 --> <div class="modal-header"> <h4 class="modal-title">Modal Heading</h4> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <!-- 模态主体 --> <div class="modal-body"> 模态主体 .. </div> <!-- 模态页脚 --> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-bs-dismiss="modal">关闭</button> </div> </div> </div> </div>
添加动画
请使用 .fade
类在打开和关闭模态时添加淡入淡出效果:
Sample
<!-- Fading modal --> <div class="modal fade"></div> <!-- Modal without animation --> <div class="modal"></div>
模态尺寸
通过为小模态添加 .modal-sm
类(max-width 300px)、为大型模态添加 .modal-lg
类(max-width 800px)或为超大模态添加 .modal-xl
来更改模态的大小(max-width 1140 像素)。默认为 500 像素最大宽度。
请将 .modal-dialog
类与尺寸类一同添加到 <div>
元素:
Small Modal
<div class="modal-dialog modal-sm">
Large Modal
<div class="modal-dialog modal-lg">
Extra Large Modal
<div class="modal-dialog modal-xl">
By default, the size of the modal is "medium" (max-width 500px).
Full screen modal
If you want the modal to span the entire width and height of the page, please use .modal-fullscreen
Class:
Sample
<div class="modal-dialog modal-fullscreen">
Responsive full screen modal
You can also use .modal-fullscreen-*-*
Class controls when the modal should be displayed full screen:
Class | Description | Example |
---|---|---|
.modal-fullscreen-sm-down |
Full screen below 576px | Try it yourself |
.modal-fullscreen-md-down |
Full screen below 768px | Try it yourself |
.modal-fullscreen-lg-down |
Full screen below 992px | Try it yourself |
.modal-fullscreen-xl-down |
Full screen below 1200px | Try it yourself |
.modal-fullscreen-xxl-down |
Full screen below 1400px | Try it yourself |
Centered modal
By using .modal-dialog-centric
Class, vertically and horizontally center the modal in the page:
Sample
<div class="modal-dialog modal-dialog-centered">
Scrolling modal
When there is a lot of content in the modal, it will add a scrollbar to the page. Please see the following examples to understand:
Sample
<div class="modal-dialog">
However, by using .modal-dialog-scrollable
Add to .modal-dialog
Can only scroll inside the modal, not the page itself:
Sample
<div class="modal-dialog modal-dialog-scrollable">
- Previous page BS5 carousel
- Next page Babban kwamiti na nuna kwanan