PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

博客列表 > 第9章 1221-浮动定位与flex初步,学习心得、笔记

第9章 1221-浮动定位与flex初步,学习心得、笔记

努力工作--周工--Robin
努力工作--周工--Robin 原创
2021年01月16日 18:38:17 558浏览

今天所学心得、笔记

1、简述定位的类型与应用场景和使用条件;

  1. CSS中定位主要有5种:
  2. 1、static:静态定位,标准文档流,系统默认使用;
  3. 2、relative 相对定位,相对元素自己之前位置(默认位置),发生偏移量的定位,不脱离文档流,下方元素不会上移挤占位置;
  4. 3、absolute 绝对定位,相对于定位元素(一般为父级元素)的位置,发生偏移量的定位,脱离了文档流,下方元素会上移挤占位置,
  5. 父元素不能是static定位,否则采用根元素html作为定位元素,所以absolute一般需要和relative配合使用,
  6. 父容器使用relative(相对定位),子容器使用absolute(绝对定位);
  7. 4、fixed 固定定位,元素一直在视口中保持固定位置的定位,脱离了文档流不占位置,一般用于广告,客服,返回头部等元素;
  8. 5、sticky 粘性定位,这里不作研究;

2、实现一个模态框;

2.1 html部分

  1. <body>
  2. <!-- 页眉 -->
  3. <header>
  4. <h2>我的博客</h2>
  5. <button>登 录</button>
  6. </header>
  7. <!-- 模态框 -->
  8. <div class="modal">
  9. <!-- 蒙板 -->
  10. <div class="modal-backboard"></div>
  11. <!-- 登录框 -->
  12. <div class="login-box">
  13. <button class="close">关闭</button>
  14. <form action="" method="post">
  15. <table>
  16. <caption>用户登录</caption>
  17. <tr>
  18. <td><label for="username">用户名 &nbsp;</label></td>
  19. <td><input type="text" id="username"></td>
  20. </tr>
  21. <tr>
  22. <td><label for="password">密 &nbsp; 码 &nbsp;</label></td>
  23. <td><input type="text" id="password"></td>
  24. </tr>
  25. <tr>
  26. <td></td>
  27. <td><button type="submit">登 录</button></td>
  28. </tr>
  29. </table>
  30. </form>
  31. </div>
  32. </div>
  33. </body>

2.2 script部分

  1. <script>
  2. // 获取元素
  3. const btn = document.querySelector('header button');
  4. const modal = document.querySelector('.modal');
  5. const close = document.querySelector('.close');
  6. // 两个按钮,添加事件
  7. btn.addEventListener('click',setModal);
  8. close.addEventListener('click',setModal);
  9. // 事件处理函数
  10. function setModal(ev) {
  11. ev.preventDefault();
  12. let status = window.getComputedStyle(modal, null).getPropertyValue('display');
  13. modal.style.display = status === 'none' ? 'block' : 'none';
  14. }
  15. </script>

案例截图

" class="reference-link">

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议