9.11 align-self

60 阅读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: center;
        }
        .parent>div{
            width: 60px;
            height: 50px;
            color: white;
        }
        .div2{
            /* 设置弹性元素自身在交叉轴的对齐方式 */
            align-self: flex-start;
        }
    </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>