9.3 justify-content

102 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .parent{
            width: 400px;
            height: 300px;
            background-color: #ccc;
            margin: 0 auto;
            display: flex;
            flex-direction: row;
            /* 更改主轴弹性元素对齐方式 默认值flex-start 主轴起点对齐 */
            /* flex-end 主轴终点对齐  center 中间对齐 */
            /* justify-content: flex-end; */

            /* 中间弹性元素空间是左右弹性元素空间的两倍 */
            /* justify-content: space-around; */

            /* 空间均匀分配 每个元素左右两侧空间相等 */
            /* justify-content: space-evenly; */

            /* 最左侧和最右侧弹性元素紧贴父容器排列 */
            /* justify-content: space-between; */

            /* 拉伸对齐平铺  默认占满父容器的高度 若给弹性元素设置height stretch失效*/
            /* justify-content: stretch; */

        }
        .parent>div{
            width: 60px;
            /* height: 50px; */
            color: white;
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="div1" style="background-color: red;">弹性元素1</div>
        <div class="div2" style="background-color: green;">弹性元素2</div>
        <div class="div3" style="background-color: blue;">弹性元素3</div>
    </div>
</body>
</html>