天天看點

flex 布局示例

flex 布局示例
<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>flex 布局 示例</title>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }

            .container {
                display: flex;
                /*主軸上如果放不下的話 換行*/
                flex-wrap: wrap;
                /*主軸對齊方式*/
                justify-content: center;
                /*交叉軸(豎軸)對齊方式 */
                align-items: center;
            }
            .item{
            }

            .item-1 {
                width: 300px;      

              /*或者*/

              flex-basis:300px;

background: #008000;
            }

            .item-2 {
                /*定義子項目的縮放比例*/
                flex: 1;
                background: #808080;
            }

            .item-3 {
                background: gold;
            }

            .item-4 {
                background: pink;
            }

            .item-5 {
                background: yellow;
            }

            .item-6 {
                background: #FFD700;
            }
        </style>
    </head>

    <body>
        <div class="container">
            <div class="item item-1">1</div>
            <div class="item item-2">2</div>
            <!--<div class="item item-3">3</div>
            <div class="item item-4">4</div>
            <div class="item item-5">5</div>
            <div class="item item-6">6</div>-->
        </div>
    </body>

</html>      
flex 布局示例