• 页面架构(笔记3)——水平垂直都居中布局


    需求要求:

    1.子容器相对父容器水平居中、垂直居中

    2,子容器与父容器的自身高度宽度都是未知的

    image image image image

    解决方案一(inline-block+text-align+table-cell+vertical-align)

    <style type="text/css">
        body{margin:20px;}
        .parent{width:200px;height:300px;}
        
        .parent{
            text-align: center;
            display: table-cell;
            vertical-align: middle;
        }
        .child{
            display: inline-block;
        }
    </style>
    
    <body>
    <div class="parent">
        <div class="child">DEMO</div>
    </div>
    </body>

    解决方案二(absolute+transform)

    <style type="text/css">
        body{margin:20px;}
        .parent{width:200px;height:300px;}
        
        .parent{
            position: relative;
        }
        .child{
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
    </style>
    
    
    <body>
    <div class="parent">
        <div class="child">DEMO</div>
    </div>
    </body>

    解决方案三(flex+justify-content+align-items)

    <style type="text/css">
        body{margin:20px;}
        .parent{width:200px;height:300px;}
        
        .parent{
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
    
    <body>
    <div class="parent">
        <div class="child">DEMO</div>
    </div>
    </body>
  • 相关阅读:
    fjnu2019第二次友谊赛 B题
    2019年FJNU低编赛 G题(dfs博弈)
    洛谷P2634 聪聪可可 (点分治)
    洛谷P3128 [USACO15DEC]最大流Max Flow (树上差分)
    Comet OJ
    Comet OJ
    Comet OJ
    Comet OJ
    Django models操作、中间件、缓存、信号、分页
    Ajax
  • 原文地址:https://www.cnblogs.com/zz334396884/p/5199422.html
Copyright © 2020-2023  润新知