zoukankan      html  css  js  c++  java
  • 图形的相对定位---绝对定位 ------ 固定定位

    相对定位:占位置

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .box{
                width:200px;
                height:200px;
                background-color:red;
                position:relative; /*相对定位占位置,后面的元素接着排列*/
                top:30px; /*在margin-top的位置基础上移动,这样就压盖了下面的图形*/
                left:40px; /*在margin-top的位置基础上移动,这样就压盖了下面的图形*/
                margin-top: 30px; /*两个div一起向下移动30px*/
            }
            .box2{
                width:200px;
                height:200px;
                background-color:green;
            }
        </style>
    </head>
    <body style="height: 2000px;">
    
    <div class="box"></div>
    <div class="box2"></div>
    
    </body>
    </html>

    绝对定位:不占位置,脱标了

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            *{
                padding: 0;
                margin: 0;
            }
            .box{
                width: 200px;
                height: 200px;
                background-color: red;
    
                /*单独设置绝对定位
                参考点:是以页面的左上角为参考点
                特点:脱标 不占位置
                */
                position: absolute; /*这样一来,两个div都占据页面的顶端*/
                top: 30px;
            }
            .box2{
                 width: 200px;
                height: 300px;
                background-color: green; /* .box的red颜色在green颜色的上面*/
            }
        </style>
    </head>
    <body style="height: 2000px">
    
        <div class="box"></div>
        <div class="box2"></div>
    
    </body>
    </html>

    嵌套盒子中子盒子的移动:

    父相子绝:父盒子相对定位,子盒子绝对定位

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            *{
                padding: 0;
                margin: 0;
            }
            .father{
                width: 500px;
                height: 500px;
                border: 1px solid yellow;
                 /*父相对定位*/
                position: relative;
                margin-left: 50px;
            }
            .box{
                width: 200px;
                height: 200px;
                background-color: red;
                /*如果是嵌套盒子
                参考点:是以最近父辈盒子的左上角为参考点*/
                position: absolute;
                top: 40px;
                left: 30px;
            }
            .box2{
                 width: 200px;
                height: 300px;
                background-color: green;
            }
        </style>
    </head>
    <body style="height: 2000px">
    <div class="father">
        <div class="box"></div>
        <div class="box2"></div>
    </div>
    </body>
    </html>

     固定定位:脱标,不占位置,以浏览器为参考点,固定位置,滑动滚动条不动

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            *{
                padding: 0;
                margin: 0;
            }
            .top{
                width: 200px;
                height: 200px;
                background-color: red;
                /*固定定位盒子脱标
                参考点: 以浏览器的左上角
                */
                position: fixed;
                bottom: 10px;
                right: 30px;
                text-align: center;
                line-height: 200px;
                color: #fff;
                font-size: 18px;
            }
        </style>
    </head>
    <body style="height: 2000px;">
    
        <div class="top">回到顶部</div>
    
        <!--1.引包 这个包来自网络-->
        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
        <script>
            console.log($);
            /* $('.top')引用 top类,click点击事件*/
            $('.top').click(function () {
                // alert(1)
                $('html,body').animate({
                    scrollTop:'0'
                },1000);
                /*1000表示一秒时间内滚动到页面顶部*/
            });
        </script>
    
    </body>
    </html>
  • 相关阅读:
    SL复习笔记之平稳转型——基础篇(二、控件和数据访问)
    UML之用例图和类图
    SL复习笔记之平稳转型——基础篇(四、多媒体,工具提示和右键菜单)
    SL复习笔记之平稳转型——基础篇(一)
    SL复习笔记之平稳转型——基础篇(三、SL安装检测和用“刷子”刷出背景)
    平稳转型WP系列之在Windows Phone中谈“委托”、“事件”和“接口”(一、深入理解)
    UML建模之活动图和StarUML使用
    SL复习笔记之平稳转型——基础篇(五、数据绑定)
    使用html parser
    设计模式工厂模式
  • 原文地址:https://www.cnblogs.com/mmyy-blog/p/9504945.html
Copyright © 2011-2022 走看看