4、flex布局容器六⼤属性之justify-content

对着背影说爱祢 提交于 2020-02-27 18:01:25

justify-content

justify-content属性设置⼦项⽬在主轴上的对⻬⽅式。

描述 示例
flex-start 默认值。左对⻬ 1
flex-end 右对⻬ 2
center 居中 3
space-between 两端对⻬,⼦项⽬之间间隔⼀样 4
space-around 每个⼦项⽬两侧的间隔⼀样 5

源码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>justify-content</title>
</head>
<style>
    .flexTest {
        display: flex;
        width: 100wh;
        border: 1px solid red;
        /* 默认值。左对⻬ */
        justify-content:flex-start;
        /* 右对⻬ */
        justify-content:flex-end;
        /* 居中 */
        justify-content:center;
        /* 两端对⻬,⼦项⽬之间间隔⼀样 */
        justify-content:space-between;
        /* 每个⼦项⽬两侧的间隔⼀样 */
        justify-content:space-around;
    }

    .item {
        width: 100px;
        height: 100px;
        background-color: gray;
        margin: 10px;
        text-align: center;
        line-height: 100px;
    }
</style>

<body>
    <h1>justify-content</h1>
    <div class="flexTest">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
    </div>
</body>

</html>

1、flex-start

2、flex-end

3、center

4、space-between

5、space-around

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!