Foundation modal box
The modal box is a pop-up window displayed at the head of the page.
We can use a unique ID on the container element (such as <div id="myModal"
) and add the .reveal-modal
class and data-reveal
attribute to add a modal box. We can use the data-reveal-id="id"
attribute on any element to open the modal box. id must be consistent with the container id (the example is "myModal").
If you want to close the modal box by clicking outside the modal box. You can add the .close-reveal-modal
class to the <a>
tag of the modal box's close button to achieve this.
Note: The slider requires JavaScript. So you need to initialize oundation JS:
Instance
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body style="padding:20px;"> <div style="padding:20px;"> <h2>模态框</h2> <p>模态框是一个显示在页面头部的弹窗。</p> <button type="button" class="button" data-reveal-id="myModal">点我打开模态框</button> <div id="myModal" class="reveal-modal" data-reveal> <h2>Heading in Modal.</h2> <p>Some text in the modal.</p> <p>Some text in the modal.</p> <a class="close-reveal-modal">×</a> </div> </div> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Modal box size
You can add the following class on the modal box container to set the size of the modal box:
.tiny
: 30% width.small
: 40% width.medium
: 60% width.large
: 70% width.xlarge
: 95% width##.full
: 100% width and height
Note: The default is 80% width on tablets, laptops, and PCs, and 100% width on small screen devices.
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>模态框大小</h2> <p>使用以下类来修改模态框大小:</p> <ul> <li><code>.tiny</code>: 设置宽度为 30%</li> <li><code>.small</code>: 设置宽度为 40%</li> <li><code>.medium</code>: 设置宽度为 60%</li> <li><code>.large</code>: 设置宽度为 70%</li> <li><code>.xlarge</code>: 设置宽度为 95%</li> <li><code>.full</code>: 设置宽度喝高度为 100%</li> </ul> <button type="button" class="button" data-reveal-id="myModal">打开小个模态框</button> <div id="myModal" class="reveal-modal tiny" data-reveal> <h2>小个模态框</h2> <p>这是一个小个模态框。尝试使用不同的类来修改模态框大小。</p> <a class="close-reveal-modal">×</a> </div> </div> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»Click the "Run Instance" button to view the online instance
Embedded modal boxYou can embed a modal box within a modal box, and you can add a new trigger button on the first modal box. You must set a unique id for the inline modal:
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>内嵌模态框</h2> <!-- 触发模态框 --> <button type="button" class="button" data-reveal-id="myModal">点击打开模态框</button> <!-- 第一个模态框 --> <div id="myModal" class="reveal-modal" data-reveal> <h2>第一个模态框</h2> <p>点击以下按钮会打开一个新的模态框。如果打开新的模态框,那么第一个模态框就会被关闭。</p> <p><a href="#" data-reveal-id="secondModal" class="button success">打开第二个模态框</a></p> <a class="close-reveal-modal">×</a> </div> <!-- 第二个模态框 --> <div id="secondModal" class="reveal-modal" data-reveal> <h2>第二个模态框</h2> <p>第二个模态框,第一个模态框已关闭。</p> <p>Foundation 让新的模态框取代了第一个模态框。</p> <a class="close-reveal-modal">×</a> </div> </div> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Example»Click "Run instance" button to view the online instance
data-options="multiple_opened:true;" attributes on the second modal box:
<!DOCTYPE html> <html> <head> <title>Foundation 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body> <div style="padding:20px;"> <h2>内嵌模态框</h2> <!-- 触发模态框 --> <button type="button" class="button" data-reveal-id="myModal">点击打开模态框</button> <!-- 第一个模态框 --> <div id="myModal" class="reveal-modal" data-reveal> <h2>第一个模态框</h2> <p>点击以下按钮会打开一个新的模态框。如果打开新的模态框,那么第一个模态框就会被关闭。</p> <p><a href="#" data-reveal-id="secondModal" class="button success" style="text-decoration:none;">打开第二个模态框</a></p> <a class="close-reveal-modal">×</a> </div> <!-- 第二个模态框 --> <div id="secondModal" class="reveal-modal" data-reveal data-options="multiple_opened:true;"> <h2>第二个模态框</h2> <p>第二个模态框,第一个模态在第二个模态框下面,并没有关闭。</p> <a class="close-reveal-modal">×</a> </div> </div> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»Click the "Run instance" button to view the online instance