• position用法


    fixed的用法
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .pg-header{
                background-color: red;
                height: 48px;
                /*添加position后可以使该div与其他div处于屏幕的不同层,fixed为将该div固定到浏览器窗口的指定位置,
                top、bottom、right、left四个方位代表了离屏幕有多少距离*/
                position: fixed;
                top: 0px;
                right: 0px;
                left: 0px;
            }
            .pg-body{
                background-color: darkgray;
                height: 5000px;
                margin-top: 50px;
            }
            .pg-back_to_top {
                background-color: black;
                color: white;
                height: 50px;
                width: 50px;
                position: fixed;
                right: 10px;
                bottom: 10px;
            }
        </style>
    </head>
    <body>
        <div class="pg-header">标题</div>
        <div class="pg-body">内容</div>
        <div onclick="GoTop();" class="pg-back_to_top">返回顶部</div>
        <script>
            function GoTop(){
                console.log("123")
                document.documentElement.scrollTop = 0;
            }
        </script>
    </body>
    </html>
    View Code

    absolute和relative用法

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <!--position的relative如果单独使用,没有任何效果,因为它是自己定义自己,对div自己没有任何实际意义。
    但如果这个div的内部还有div,而且这个内部的div想要定义自己相对于父div的位置,就需要在自己的position
    属性添加absolute-->
        <div style="position:relative; 500px;height: 200px;border: 1px solid red;margin: 0 auto">
            <div style="position: absolute;bottom: 0px; 50px;height: 50px;background-color: black"></div>
        </div>
        <div style="position:relative; 500px;height: 200px;border: 1px solid red;margin: 0 auto">
            <div style="position: absolute;top: 0px;right: 0px; 50px;height: 50px;background-color: black"></div>
        </div>
        <div style="position:relative; 500px;height: 200px;border: 1px solid red;margin: 0 auto">
            <div style="position: absolute;top: 0px; 50px;height: 50px;background-color: black"></div>
        </div>
    </body>
    </html>e
    View Code

    z-index属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <!--z-index可以设置层级页面的优先级,值越大,优先级越高,优先级高的放在最上面-->
        <div style="z-index: 10;background-color: white;position: fixed;height: 200px; 400px;
        top: 50%;left: 50%;margin-top: -200px;margin-left: -200px">
            <input type="text"/>
            <input type="text"/>
            <input type="text"/>
        </div>
        <div style="z-index:9;position: fixed;background-color: darkgray;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        /*opacity属性为设置div的透明度,值越大,背景色越深*/
        opacity: 0.5"></div>
        <div style="height: 5000px;background-color: green">第一层页面</div>
    </body>
    </html>
    View Code
  • 相关阅读:
    总结对象和数组存储东东的缺点和优点
    this关键字
    修改对象属性的方法
    调用对象属性的两种方式
    数组可储存的东西
    对比字面量和结构函数创建对象的相同之处和不同之处
    构造函数创建对象
    字面量创建对象
    SQL语句
    使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)
  • 原文地址:https://www.cnblogs.com/ttyypjt/p/10339164.html
Copyright © 2020-2023  润新知