博主信息
博文 7
粉丝 0
评论 0
访问量 5121
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
实例演示:模态框
原创
1176人浏览过

代码

html

  1. <body>
  2. <header>
  3. <h1 class="title">千千的博客</h1>
  4. <button onclick="showModal()">登录</button>
  5. </header>
  6. <!-- 模态框 -->
  7. <div class="modal">
  8. <!-- 1.半透明的遮罩 -->
  9. <div class="modal-bg" onclick="closeModal()"></div>
  10. <form action="" class="modal-form">
  11. <fieldset style="display: grid; gap: 1em">
  12. <legend>用户登录</legend>
  13. <input type="email" name="email" placeholder="user@email.com" />
  14. <input type="password" name="password" placeholder="不少于6位" />
  15. <button>登录</button>
  16. </fieldset>
  17. </form>
  18. </div>
  19. <script src="modal.js"></script>
  20. </body>

css样式

<link rel="stylesheet" href="modaltext.css">

  1. /* 初始化 */
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 头部 */
  8. header{
  9. background-color: coral;
  10. padding: 2em 5em;
  11. display: flex;
  12. }
  13. /* logo */
  14. header .title{
  15. font-weight:lighter;
  16. font-style:italic;
  17. color:grey;
  18. letter-spacing:50px;
  19. text-shadow: 1px 1px 1px white
  20. }
  21. /* 登录按钮 */
  22. header button{
  23. margin-left: auto;
  24. margin-top: auto;
  25. width: 6em;
  26. height: 2em;
  27. border: none;
  28. border-radius:0.5em;
  29. }
  30. header button:hover{
  31. cursor: pointer;
  32. background-color: coral;
  33. color: white;
  34. box-shadow: 0 0 10px #fff;
  35. transition: 0.5s;
  36. }
  37. /* 模态框 */
  38. .modal .modal-form fieldset {
  39. height:15.5em;
  40. background-color: lightsalmon;
  41. border: none;
  42. padding: 2em 3em;
  43. box-shadow:0 0 10px #888;
  44. }
  45. /* 模态框表单标题 */
  46. .modal .modal-form fieldset legend {
  47. padding:7px 1.5em;
  48. color: #fff;
  49. border:solid white 0.5px;
  50. background-color: orange;
  51. }
  52. .modal .modal-form fieldset input {
  53. height:3em;
  54. padding-left:1em;
  55. border: 1px solid #DDD;
  56. outling:none;
  57. font-size: 14px;
  58. }
  59. /* :focus: 表单控件,获取焦点时的样式 */
  60. .modal .modal-form fieldset input:focus {
  61. box-shadow:0 0 10px rgb(90, 90, 90);
  62. border:none;
  63. }
  64. .modal .modal-form fieldset button{
  65. background-color: orange;
  66. color:white;
  67. border:none;
  68. height:3em;
  69. font-size:16px;
  70. height:2.5em;
  71. box-shadow:0 0 10px white;
  72. }
  73. .modal .modal-form fieldset button:hover{
  74. background-color:coral;
  75. /* cursor: 网页浏览时用户鼠标指针的样式或图形形状。pointer:光标为一只手 */
  76. cursor:pointer;
  77. }
  78. /* 定位 */
  79. .modal .modal-form {
  80. position:fixed;
  81. top:10em;
  82. left:35em;
  83. right:35em;
  84. }
  85. /* 遮罩 */
  86. .modal .modal-bg {
  87. position: fixed;
  88. /* 坐标全部清零,定位到四个顶点 */
  89. top: 0;
  90. left: 0;
  91. right: 0;
  92. bottom: 0;
  93. background-color: rgb(0,0,0,0.5);
  94. }
  95. .modal{
  96. display:none;
  97. }

效果


批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学