博主信息
博文 29
粉丝 0
评论 0
访问量 25175
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
定位类型、模态框
手机用户1576673622
原创
917人浏览过

定位类型

  1. 静态定位: position: static 默认,也就是文档流定位,元素的显示位置与源码顺序一致(不是定位元素)
  2. 相对定位: position: relative;相对于该元素在文档流中的原始位置进行偏移
  3. 绝对定位: position: absolue;相对于它的祖先中离它最近的”定位元素”的位置发生偏移(如果祖先元素中不存在定位元素,它就参考根元素(html)进行定位)
  4. 固定定位: position: fixed; 是绝对定位的一个特例,它始终相对于html定位
  • 定位元素:只要这个元素中有position: relative;或者 position:absolute;就称为定位元素

    模态框

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>模态框</title>
    8. <link rel="stylesheet" href="style1.css">
    9. </head>
    10. <body>
    11. <!-- 页眉 -->
    12. <header>
    13. <h2>百度一下</h2>
    14. <button>登录</button>
    15. </header>
    16. <!-- 模态框 -->
    17. <div class="modal">
    18. <!-- 蒙板。用来盖住后面的内容,使其透明化 -->
    19. <div class="modal-backdrop"></div>
    20. <div class="modal-body">
    21. <button class="close">关闭</button>
    22. <form action="" method="POST">
    23. <table>
    24. <caption>用户登录</caption>
    25. <tr>
    26. <td><label for="name">用户名:</label></td>
    27. <td><input type="name" name="name" id="name"></td>
    28. </tr>
    29. <tr>
    30. <td><label for="password">密码:</label></td>
    31. <td><input type="password" name="password" id="password"></td>
    32. </tr>
    33. <tr>
    34. <td><button>登录</button></td>
    35. </tr>
    36. </table>
    37. </form>
    38. </div>
    39. </div>
    40. </body>
    41. </html>

    css

    1. *{
    2. margin: 0;
    3. padding: 0;
    4. box-sizing: border-box;
    5. }
    6. header {
    7. background-color: #ccc;
    8. margin: 0.5em 1em;
    9. overflow: hidden;
    10. }
    11. header h2 {
    12. float: left;
    13. }
    14. header button {
    15. float:right;
    16. width: 10em;
    17. height: 2.5em;
    18. }
    19. header button:hover{
    20. cursor: pointer;
    21. background-color: #fff;
    22. }
    23. /* 模态框 */
    24. /* 蒙板 */
    25. .modal .modal-backdrop{
    26. background-color: rgb( 0,0,0,0.5);
    27. position: fixed;
    28. top: 0;
    29. left: 0;
    30. right: 0;
    31. bottom: 0;
    32. }
    33. /* 主体 */
    34. .modal .modal-body{
    35. padding: 1em;
    36. min-width: 20em;
    37. border: 1px solid #ccc;
    38. background: linear-gradient(to right, lightcyan, #fff);
    39. /* 固定定位 */
    40. position: fixed;
    41. top: 5em;
    42. right: 20em;
    43. left: 20em;
    44. }
    45. /* 页面初始化时,模态框应该隐藏 */
    46. /* .modal {
    47. display: none;
    48. } */
批改老师:天蓬老师天蓬老师

批改状态:合格

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

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

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