9.4 交叉轴对齐方式align-items

113 阅读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;
            /* 更改交叉轴对齐方式 align-items */
            /* 默认值felx-start 上对齐
            flex-end 右对齐
            center 居中对齐
            */
            /* align-items: flex-end; */

            /* 平铺 拉伸 设置height 不生效*/
            /* align-items: stretch; */

            /* 基线对齐  弹性元素文字上方对齐 baseline*/
            align-items: baseline;
        }
        .div2{
            padding-top: 20px;
        }
        .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>