父盒子设置弹性布局使子盒子垂直水平居中

编程入门 行业动态 更新时间:2024-10-15 14:13:00

         .container{
            width: 500px;
            height: 600px;
            background-color: pink;
            /* 设置为弹性盒子 默认横向摆放*/
            display: flex;

            /* 改变弹性盒子摆放方式
            flex-direction: row | row-reverse | column | column-reverse
            row 默认横向 
            row-reverse 横向反转 类似右浮动
            column 纵向排列
            column-reverse 纵向反转 
            */
            flex-direction: column;

            /* justify-content:flex-start|flex-end|center 
                垂直方向的摆放
            */
            justify-content: center;
            /* 水平方向 */
            /*align-items:  flex-start 居左摆放 |flex-end 居右摆放|center 居中摆放*/
            align-items: center;
        
        }
        .box1{
            height: 50px;
            width: 50px;
            background-color: red;
        }
        .box2{
            height: 50px;
            width: 50px;
            background-color: blue;
        }
        .box3{
            height: 50px;
            width: 50px;
            background-color: green;
        }
 

```html
    <div class="container">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
    </div>

更多推荐

父盒子设置弹性布局使子盒子垂直水平居中

本文发布于:2023-06-13 12:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1381901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:盒子   弹性   布局   水平

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!