Blogger Information
Blog 6
fans 0
comment 0
visits 2968
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
动态框案例
Breeze blue sea
Original
332 people have browsed it

动态框案例

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. }

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:登录框的固定定位位置可适当优化
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post