移动web:flex-direction、flex-warp

190 阅读1分钟

主轴方向: flex-direction

  • flex-direction: row;

    flex-direction默认属性

    行, 水平方向排列

image.png

  • flex-direction: column;

    列, 垂直方向排列

image.png

  • flex-direction: row-reverse;

    行, 从右向左排列

image.png

  • flex-direction: column-reverse;

    列, 从下到上排列

image.png

<!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>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        li {
            list-style: none;
        }

        .box {
            width: 400px;
            height: 400px;
            display: flex;
            /* flex-direction: row; */
            /* flex-direction: column; */
            /* flex-direction: row-reverse; */
            flex-direction: column-reverse;
            border: 1px solid #000;
            background: pink;
            margin: 50px;
        }

        .box li {
            width: 100px;
            height: 100px;
            line-height: 100px;
            background: #6cf;
            text-align: center;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <ul class="box">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>
</body>

</html>

弹性盒子换行: flex-warp

未换行:

一行全部显示, 盒子宽度会被压缩

image.png

  • 实现弹性盒子多行排列效果flex-warp: warp;

image.png

  • align-content

    • 调整对齐方式(行)

    • : flex-start(默认)

    • : flex-end

    • : center

    • : space-around

    • : space-between

    • : space-evenly

    **eg: align-content: center

image.png

  • 可以直接在上面完整的代码上直接修改完成 flex: wrap
  • 代码可以配合justify-content: xxx等代码使用以达成自己想要实现的效果
  • flex-wrap: wrap; 实现换行后. 默认情况下,如果高度未填满父盒子的高度, 则每一行平均分配给每一行