博主信息
博文 56
粉丝 0
评论 4
访问量 48423
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
CSS:模态框定位实战
异乡客
原创
842人浏览过

  1. <!DOCTYPE html>
  2. <html lang="en">
  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. <body>
  10. <header>
  11. <h2 class="title">朱老师的blog</h2>
  12. <button onclick="document.querySelector('.modal').style.display='block'" >登录</button>
  13. </header>
  14. <!-- 模态框 -->
  15. <div class="modal">
  16. <!-- 1 半透明遮罩 -->
  17. <div class="modal-bg" onclick="this.parentNode.style.display='none'"></div>
  18. <!-- 2 弹层表单 -->
  19. <form action="" class="modal-form">
  20. <fieldset>
  21. <legend>用户登录</legend>
  22. <input type="email" name="email" placeholder="usename@emial.com">
  23. <input type="password" name="password" placeholder="***********">
  24. </fieldset>
  25. </form>
  26. </div>
  27. </body>
  28. <style>
  29. /* 初始化 */
  30. *{
  31. margin:0;
  32. padding:0;
  33. box-sizing: border-box;
  34. }
  35. /* 头部样式*/
  36. header{
  37. background-color: seagreen;
  38. display: flex;
  39. padding: 0.5em 1em;
  40. }
  41. header .title{
  42. font-weight: lighter;
  43. font-style: italic;
  44. color:white;
  45. text-shadow: 1px 1px 1px;
  46. letter-spacing: 1px;
  47. }
  48. header button{
  49. margin-left:auto;
  50. width:5em;
  51. border: none;
  52. border-radius: 8px;
  53. }
  54. header button:hover{
  55. cursor: pointer;
  56. background-color: coral;
  57. color: white;
  58. box-shadow: 0 0 5px white;
  59. transition: 0.3s;
  60. }
  61. /* 模态框 */
  62. .modal .modal-form fieldset legend{
  63. padding: 5px 1em;
  64. background-color: rebeccapurple;
  65. color: white;
  66. }
  67. /* 表单的固定定位:正中间 */
  68. .modal .modal-form{
  69. position: fixed;
  70. top:10em;
  71. left:20em;
  72. right: 20em;
  73. /* background-color: lightpink; */
  74. }
  75. /* 半透明的遮罩 */
  76. .modal .modal-bg{
  77. position: fixed;
  78. /* height: 100px; */
  79. background-color: rgb(0,0,0,0.5);
  80. top:0;
  81. left:0;
  82. right:0;
  83. bottom:0;
  84. }
  85. </style>
  86. </html>

本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学