zoukankan      html  css  js  c++  java
  • 05. flex元素水平垂直居中(三种position水平垂直居中和两种新老版本水平垂直居中)

    flex元素水平垂直居中(三种position水平垂直居中和两种新老版本水平垂直居中)
    (1).position :

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }
    
            #wrap {
                 500px;
                height: 500px;
                background: grey;
                
                //新版本flex方法
                display: flex;
                justify-content: center; //主轴
                align-items: center;     //侧轴
                
                //旧版本的flex版本
                display: -webkit-box;
                -webkit-box-pack: center; //主轴
                -webkit-box-align: center;//侧轴
                
                // position: relative;
            }
            #box{
                 200px;
                height: 200px;
                background: deeppink;
                position: absolute;
                
                //第一种垂直居中法
                top: 0;
                left: 0;
                bottom: 0;
                right: 0;
                margin: auto;
                
                //第二种垂直居中法
                
                top: 50%;
                left: 50%;
                margin-top: -100px;
                margin-left: -100px;
                
                //第三种垂直居中法
                
                top: 50%;
                left: 50%;
                transform: translate(-50%,-50%);
            }
        </style>
    </head>
    <body>
    <div id="wrap">
        <div id="box"></div>
    </div>
    </body>
    <script type="text/javascript">
        window.onload = function () {
            var box = document.getElementById('box');
        }
    </script>
    </html>
    

      

  • 相关阅读:
    个人网站开发之用户模块
    个人网站开发记录(三)
    第二章 python变量及文件
    第十二章 函数的----
    第十一章 函数的参数
    第十章 函数
    第九章 内存管理
    第八章 文件的处理
    第七章 字符编码
    第六章 数据类型——元组、字典、集合、数据类型的转换
  • 原文地址:https://www.cnblogs.com/Lolita-web/p/10457727.html
Copyright © 2011-2022 走看看