博主信息
博文 6
粉丝 0
评论 0
访问量 5529
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
动态框案例
Breeze blue sea
原创
600人浏览过

动态框案例

1.案例图


2.搭建登入页面

  1. /html
  2. <header>
  3. <h2 class="title">夏天的个人博客</h2>
  4. <button onclick="showModal()">登入</button>
  5. </header>
  6. /css
  7. *{
  8. padding: 0px;
  9. margin: 0px;
  10. box-sizing: border-box;
  11. }
  12. header {
  13. background-color: lightblue;
  14. display: flex;
  15. padding: 0.5em 1em;
  16. }
  17. h2.title {
  18. font-weight: lighter;
  19. font-style: italic;
  20. color: #f66;
  21. letter-spacing: 2px;
  22. text-shadow: 1px 1px 1px #555;
  23. }
  24. header button {
  25. margin-left: auto;
  26. width: 5em;
  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 5px #fff;
  35. transition: 0.5s;
  36. }



3.搭建我们动态框页面

  1. /html
  2. <div class="modal">
  3. <div class="modal-bg" onclick="closeModal()"></div>
  4. <form action="" class="modal-form">
  5. <fieldset style="display: grid; gap: 1em;">
  6. <legend>用户登入</legend>
  7. <input type="email" name="email" placeholder="user@email.com">
  8. <input type="password" name="password" placeholder="不少于8位数">
  9. <button>登入</button>
  10. </fieldset>
  11. </form>
  12. </div>
  13. /css
  14. .modal .modal-form fieldset {
  15. height: 15.5em;
  16. background-color: lightcyan;
  17. border: none;
  18. padding: 2em 3em;
  19. box-shadow: 0 0 5px #888;
  20. }
  21. .modal .modal-form fieldset legend {
  22. padding: 7px 1.5em;
  23. color: white;
  24. background-color: lawngreen;
  25. }
  26. .modal .modal-form fieldset input {
  27. height: 3em;
  28. padding-left: 1em;
  29. outline: none;
  30. border: 1px solid #ddd;
  31. font-size: 14px;
  32. }
  33. .modal .modal-form fieldset input:focus {
  34. box-shadow: 0 0 8px #888;
  35. border: none;
  36. }
  37. .modal .modal-form fieldset button {
  38. background-color: lightgreen;
  39. color: white;
  40. height: 2.5em;
  41. font-size: 16px;
  42. border: none;
  43. }
  44. .modal .modal-form fieldset button:hover {
  45. background-color: coral;
  46. cursor: pointer;
  47. }
  48. .modal .modal-form {
  49. position: fixed;
  50. top: 10em;
  51. left: 38em;
  52. right: 38em;
  53. }
  54. .modal .modal-bg {
  55. position: fixed;
  56. top: 0;
  57. left: 0;
  58. right: 0;
  59. bottom: 0;
  60. background-color: rgba(0,0,0,0.5);
  61. }
  62. .modal {
  63. display: none;
  64. }

4.通过js实现动态框页面

  1. function showModal() {
  2. // 获取模态框元素
  3. const modal = document.querySelector('.modal');
  4. // 显示模态框
  5. modal.style.display = 'block';
  6. // 焦点自动置入第一个输入框email
  7. modal.querySelector('input:first-of-type').focus();
  8. }
  9. function closeModal() {
  10. // 获取模态框元素
  11. const modal = document.querySelector('.modal');
  12. // 关闭模态框
  13. modal.style.display = 'none';
  14. }

批改老师: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+教程免费学