学习flex布局

39 阅读1分钟

快速开发框架都挺不错,但同时也有很多是用不上的。自己动手慢慢积累一个适合自己的...

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>
    <link rel="stylesheet" href="style.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            text-decoration: none;
            font-size: 14px;
            line-height: 1.3em;
        }

        .text--center {
            text-align: center;
        }

        .bg-secondary {
            background-color: lightgray;
        }

        .d-flex {
            display: flex;
        }

        .flex--row {
            flex-direction: row;
        }

        .flex--row>.col {
            flex: 1;
            background-color: lightgray;
        }

        .flex--column {
            flex-direction: column;
        }

        .flex--column>.col {
            background-color: lightgray;
        }

        .justify-content--center {
            justify-content: center;
        }

        .justify-content--between {
            justify-content: space-between;
        }

        .align-items--center {
            align-items: center;
        }

        .flex-fill {
            flex: 1, 1, 0;
        }

        .my-10 {
            margin-top: 10px;
            margin-bottom: 10px;
        }

        .my-20 {
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .my-30 {
            margin-top: 30px;
            margin-bottom: 30px;
        }

        .my-50 {
            margin-top: 50px;
            margin-bottom: 50px;
        }

        .mx-10 {
            margin-left: 10px;
            margin-right: 10px;
        }

        .mx-20 {
            margin-left: 20px;
            margin-right: 20px;
        }

        .mx-30 {
            margin-left: 30px;
            margin-right: 30px;
        }

        .mx-50 {
            margin-left: 50px;
            margin-right: 50px;
        }
    </style>
</head>

<body>

    <div class="d-flex flex--row my-20 mx-20">
        <div class="col text--center">col1</div>
        <div class="col">col2内容</div>
        <div class="col">col3内容比较多</div>
    </div>

    <div class="d-flex flex--column my-20 mx-20">
        <div class="col">col1</div>
        <div class="col">col2</div>
        <div class="col">col3</div>
    </div>

    <div class="d-flex justify-content--center bg-secondary align-items--center" style="height: 100px;">
        <div class="col">水平居中1</div>
        <div class="col">水平居中2</div>
        <div class="col">水平居中3</div>
    </div>

    <div class="d-flex justify-content--between my-50 mx-20 bg-secondary align-items--center" style="height: 100px;">
        <div>水平居中1</div>
        <div>水平居中2</div>
        <div>水平居中3</div>
    </div>

    <div class="d-flex flex--column justify-content--center my-50 mx-20 bg-secondary align-items--center"
        style="height: 100px;">
        <div>水平居中1</div>
        <div>水平居中2</div>
        <div>水平居中3</div>
    </div>
</body>

</html>