9.8 flex-grow

56 阅读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;
        }
        .parent>div{
            width: 60px;
            height: 50px;
            color: white;
        }
        .div1{
            /* 默认父容器有剩余空间时不会放大 不会占满父容器剩余空间 */
            /* flex-grow 默认值0 弹性元素默认不放大 */
            flex-grow: 1;
        }
        .div2{
            flex-grow: 1;
        }
        .div3{
            flex-grow: 1;
        }
    </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>