模态框小实例

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>模态框-留言板</title>
  8. </head>
  9. <style>
  10. *{
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. .notes{
  16. width: 100px;
  17. height: 100px;
  18. background-color: coral;
  19. position: fixed;
  20. top: 200px;
  21. right: 0;
  22. text-align: center;
  23. line-height: 100px;
  24. color: #fff;
  25. }
  26. /* 遮罩层 */
  27. .modal .modal-bg{
  28. position: fixed;
  29. /* 坐标全部清0,请定位到四个顶点 */
  30. top: 0;
  31. right: 0;
  32. bottom: 0;
  33. left: 0;
  34. background-color: rgb(0,0,0,.5);
  35. }
  36. /* 弹出层模态框 */
  37. /* 定位 */
  38. .modal .modal-form {
  39. position: fixed;
  40. top: 10em;
  41. left: 28em;
  42. right: 28em;
  43. }
  44. .modal .modal-form fieldset {
  45. height: 22em;
  46. background-color: lightcyan;
  47. border: none;
  48. padding: 2em 3em;
  49. box-shadow: 0 0 5px #888;
  50. }
  51. .modal .modal-form fieldset legend{
  52. color: #fff;
  53. background-color: coral;
  54. padding: 8px 2em;
  55. }
  56. .modal .modal-form fieldset textarea{
  57. width:45em;
  58. outline: none;
  59. border: 1px solid #ddd;
  60. font-size: 14px;
  61. margin-top: 8px;
  62. }
  63. .modal .modal-form fieldset input{
  64. width:22em;
  65. outline: none;
  66. border: 1px solid #ddd;
  67. font-size: 14px;
  68. margin-top: 8px;
  69. height: 30px;
  70. margin-left: 8px;
  71. }
  72. .modal .modal-form fieldset button{
  73. width: 14em;
  74. margin-left: 10px;
  75. outline: none;
  76. border: 1px solid #ddd;
  77. height: 30px;
  78. background-color: coral;
  79. cursor: pointer;
  80. color: #fff;
  81. }
  82. .modal{
  83. display: none;
  84. }
  85. </style>
  86. <script>
  87. //显示模态框
  88. function showModal(){
  89. //获取模态框元素
  90. const modal = document.querySelector('.modal');
  91. //显示模态框
  92. modal.style.display = 'block';
  93. //焦点自动置入第一个文本域
  94. modal.querySelector('textarea').focus();
  95. }
  96. //关闭模态框
  97. function closeModal(){
  98. //获取模态框元素
  99. const modal = document.querySelector('.modal');
  100. //关闭模态框
  101. modal.style.display = 'none';
  102. }
  103. </script>
  104. <body>
  105. <div class="notes" onclick="showModal()">点我留言</div>
  106. <!-- 模态框 -->
  107. <div class="modal">
  108. <!-- 模态框遮罩层 -->
  109. <div class="modal-bg" onclick="closeModal()"></div>
  110. <!-- 弹出层 -->
  111. <div class="modal-form">
  112. <fieldset>
  113. <legend>市长信箱</legend>
  114. <label for="your-notes">您的留言:</label><textarea name="notes" id="your-notes" cols="30" rows="10" placeholder="请输入您的留言"></textarea>
  115. <label for="your-email">您的邮箱:</label><input type="email" name="email" id="your-email" placeholder="请输入您的邮箱如:123@com">
  116. <button>提 交</button>
  117. </fieldset>
  118. </div>
  119. </div>
  120. </body>
  121. </html>

模态框实例

更多相关文章

  1. android 布局实例解析 柱状图效果
  2. Activity的启动模式(android:launchMode)
  3. 【JNI】 Android(安卓)JNI入门实例(Windows+Cygwin+Eclipse)
  4. Yii2使用驼峰命名的形式访问控制器(实例讲解)
  5. php 重写分页器 CLinkPager的实例
  6. 选项卡和购物车实例
  7. 简单实例:图文列表、表格(课程表)
  8. Android动态显示隐藏密码输入框的内容
  9. ExpandableListView用法实例

随机推荐

  1. Android 自定义URL Scheme
  2. fanfou(饭否) android客户端 代码学习3
  3. 学习Android(安卓)Opengles 做游戏引擎笔
  4. Google Android 2.0初期版本亮相 支持手
  5. Android之——史上最简单最酷炫的3D图片
  6. Android UI学习总结
  7. xmlns:android="http://schemas.android.
  8. 使用VirtualBox在PC上安装Android OS
  9. Android学习感想一
  10. Android开发学习笔记:Android很有用的代码