9.2 flex-wrap

131 阅读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: 300px;
            height: 250px;
            background-color: #ccc;
            margin: 0 auto;
            display: flex;
            flex-direction: row;
            /* 父容器的宽度不足以放下所有一个弹性元素时 不会进行换行显示 而是进行等比例压缩 */
            /* 设置换行显示 默认是不换行nowrap wrap换行 wrap-reverse换行反转 */
            flex-wrap: wrap;
            /* flex-flow时flex-direction和flex-wrap属性的简写 */
            flex-flow: column nowrap;
        }
        .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 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>