站长资讯网
最全最丰富的资讯网站

bootstrap的模态框在哪是什么

bootstrap的模态框是覆盖在父窗体上的,是一个子窗体;模态框的目的是显示来自一个单独的源内容,可以在不离开父窗体的情况下有一些互动,子窗体可以提供信息交互等等,可以通过添加“.modal-sm”类来创建一个小模态框,添加“.modal-lg”类创建一个大模态框。

bootstrap的模态框在哪是什么

本教程操作环境:Windows10系统、bootstrap5版、DELL G3电脑

bootstrap的模态框在哪是什么

模态框(Modal)是覆盖在父窗体上的子窗体。通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动。子窗体可提供信息交互等。

如何创建模态框

以下实例创建了一个简单的模态框效果 :

<!DOCTYPE html> <html> <head>   <title>Bootstrap 实例</title>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">   <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>   <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>   <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container">   <h2>模态框实例</h2>   <!-- 按钮:用于打开模态框 -->   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">     打开模态框   </button>       <!-- 模态框 -->   <div class="modal fade" id="myModal">     <div class="modal-dialog">       <div class="modal-content">             <!-- 模态框头部 -->         <div class="modal-header">           <h4 class="modal-title">模态框头部</h4>           <button type="button" class="close" data-dismiss="modal">&times;</button>         </div>             <!-- 模态框主体 -->         <div class="modal-body">           模态框内容..         </div>             <!-- 模态框底部 -->         <div class="modal-footer">           <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>         </div>           </div>     </div>   </div>    </div> </body> </html>

输出结果:

bootstrap的模态框在哪是什么

模态框尺寸

我们可以通过添加 .modal-sm 类来创建一个小模态框,.modal-lg 类可以创建一个大模态框。

尺寸类放在 <div>元素的 .modal-dialog 类后 :

<!DOCTYPE html> <html> <head>   <title>Bootstrap 实例</title>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">   <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>   <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>   <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container">   <h2>模态框实例</h2>   <!-- 按钮:用于打开模态框 -->   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">     打开模态框   </button>       <!-- 模态框 -->   <div class="modal fade" id="myModal">     <div class="modal-dialog modal-sm">       <div class="modal-content">             <!-- 模态框头部 -->         <div class="modal-header">           <h4 class="modal-title">模态框头部</h4>           <button type="button" class="close" data-dismiss="modal">&times;</button>         </div>             <!-- 模态框主体 -->         <div class="modal-body">           模态框内容..         </div>             <!-- 模态框底部 -->         <div class="modal-footer">           <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>         </div>           </div>     </div>   </div>    </div> </body> </html>

输出结果:

bootstrap的模态框在哪是什么

赞(0)
分享到: 更多 (0)