flex 布局 上下左右居中


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>居中</title>
    <style type="text/css">
        .box{
            display: flex;
            width: 100%;
            height: 500px;
            border: 1px solid #333;
            flex-direction: row;  /* 子元素横向排列 */
            justify-content: center; /* 相对父元素水平居中 */
            align-items: center; /*  子元素相对父元素垂直居中 */

        }
        .cont{
            width: 30%;
            height: 100px;
            border: 1px solid red;
            flex-grow:1;/* 属性用于设置或检索弹性盒的扩展比率。 */
            
            
        }




    </style>
</head>
<body>
    <div class="box">
        <div class="cont">aaaaa</div>
        <div class="cont">aaaaa</div>
    </div>
</body>
</html>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM