Flex佈局03:flex-continer && justify-content(改變flex-items在主軸上的對齊方式)

justify-content: 決定flex items 在主軸上的對齊方式

image-20210224132135756

  • flex-start

    image-20210224132217625

  • flex-end

    image-20210224132252272

  • center

    image-20210224132450955

  • space-between

    image-20210224132552425

  • space-evenly

    image-20210224132653706

  • space-around

    image-20210224132717585

代碼

<!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>
        #box{
            /* 開啓flex佈局:塊元素 */
            display: flex;
            /* 開啓flex佈局;行元素 */
            /* display: inline-flex; */
            background-color: red;
            width: 600px;
            /* 水平居中 */
            margin: 0 auto;
            /* flex-start: 默認值 main start對齊 
            flex-end: main end 對齊
            center: 主軸中間對齊
            space-between: 左右對齊等分主軸
            space-around: 左右等分間隙然後等分
            space-evenly: 左右窄,中間等分
            */
            justify-content: space-around;

        }
        .item{
            text-align: center;
            line-height: 100px;
            width: 100px;
        }

        .item1{
            background-color: azure;
        }
        .item2{
            background-color: green;
        }
        .item3{
            background-color: gold;
        }
    </style>
</head>
<body>

    <div id="box">
        <div class="item item1">item1</div>
        <div class="item item2">item2</div>
        <div class="item item3">item3</div>
    </div>
    <strong>行類元素</strong>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章