骰子的flex布局

一、一个项目

①左上角

/样式
<style>
        /* * {
            margin: 0;
            padding: 0;
        } */

        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
    </style>

///结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

 ②第一行的中间

<style>
        /* * {
            margin: 0;
            padding: 0;
        } */

        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;

            /* 将项目放在容器水平主轴的中间 */
            justify-content: center;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
    </style>


/结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

 ③当前项目在第一行的尾部

 <style>
    
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;

            /* 将项目放在容器水平主轴的尾部 */
            justify-content: flex-end;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
 </style>

结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

 ④当前项目放在第二行的第一个

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;

            /* 将项目放在容器垂直主轴的中间 */
            align-items: center;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
</style>

/结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

 ⑥正中间(垂直水平居中)

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将项目放在容器正中间*/
            justify-content: center;
            align-items: center;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
</style>

//结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

 ⑥第二行的最后

 <style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将项目放在容器中间一行的最后一个*/
            justify-content: flex-end;
            align-items: center;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
  </style>

//结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

⑦第三行的第一个位置

 

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将项目放在容器第三行的第一个*/
            align-items: flex-end;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
</style>

//结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

 ⑧当前项目放在第三行的第二个

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将项目放在容器第三行的第二个*/
            justify-content: center;
            align-items: flex-end;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
</style>

结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

效果展示:

⑨第三行的最后一个

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将项目放在容器第三行的最后一个*/
            justify-content: flex-end;
            align-items: flex-end;
        }

        .item {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
 </style>

/结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item"></div>
    </div>
</body>

 效果展示:

 二、两个项目

①第一行的左右两边各一个

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将两个项目放在第一行的左右两边*/
            justify-content: space-between;
        }

        .item1,
        .item2 {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
 </style>

/结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
    </div>
</body>

效果展示:

② 放在第二列的首尾

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将两个项目放在第二列的上下各一个*/
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
        }
        .item1,
        .item2 {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
  </style>

//结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
    </div>
</body>

效果展示:

③放在第三列的首尾两个位置

<style>
        .container {
            width: 100px;
            height: 130px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /* 将两个项目放在第三列的上下各一个*/
            flex-direction: column;
            justify-content: space-between;
            align-items: flex-end;
        }

        .item1,
        .item2 {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: black;
        }
 </style>

///结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
    </div>
</body>

 效果展示:

④ 预期效果展示:

 实现(align-self)

<style>
        .container {
            width: 100px;
            height: 100px;
            background-color: white;
            border: 1px solid black;
            display: flex;
        }

        .item1,
        .item2 {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: black;
        }

        /* 为第二个项目单独设置交叉轴的排列方式 */
        .item2 {
            align-self: center;
        }
 </style>

/结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
    </div>
</body>

效果展示:

⑤ 预期效果

实现

<style>
        .container {
            width: 100px;
            height: 100px;
            background-color: white;
            border: 1px solid black;
            display: flex;

            /*   变动1   */
            justify-content: space-between;
        }

        .item1,
        .item2 {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: black;
        }

        /*   变动2   */
        .item2 {
            align-self: flex-end;
        }
 </style>

/结构
<body>
    <!-- 一个点在左上角 -->
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
    </div>
</body>

 效果展示:

 三、三项目

①主对角线上三个

 .container {
            width: 100px;
            height: 100px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /*   变动1   */
            justify-content: space-around;
        }

        .item1,
        .item2,
        .item3 {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: black;
        }

        /*   变动2   */
        .item2 {
            align-self: center;
        }

        /*   变动3  */
        .item3 {
            align-self: flex-end;
        }
 </style>

/结构
<body>
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
        <div class="item3"></div>
    </div>
</body>

效果展示:

四、四项目

①预期效果展示

 实现:

<style>
        .container {
            width: 90px;
            height: 90px;
            background-color: white;
            border: 1px solid black;
            display: flex;
            /*   变动1   */
            flex-wrap: wrap;
            justify-content: flex-end;
            align-items: space-between;
        }

        .item1,
        .item2,
        .item3,
        .item4 {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: black;
        }

        /* 变动2 */
        .item4 {
            align-self: flex-end;
        }
    </style>

/结构
<body>
    <div class="container">
        <div class="item1"></div>
        <div class="item2"></div>
        <div class="item3"></div>
        <div class="item4"></div>
    </div>
</body>

效果展示:

 ②预期效果展示

 实现:

<style>
        /* 首先两个box交叉轴方向放置,且两个box中间有间距 */
        .container {
            width: 100px;
            height: 100px;
            border: 1px solid black;
            display: flex;
            /* 交叉轴放置 */
            flex-direction: column;
            /* 中间有间距 */
            align-content: space-around;
        }

        .item {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #000;
        }

        /* 给每个box设置弹性布局 */
        .box1,
        .box2 {
            display: flex;
            width: 100px;
            height: 45px;
            justify-content: space-around;
        }
    </style>

/结构
<body>
    <div class="container">
        <div class="box1">
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="box2">
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>
</body>

效果展示:

五、六项目 

①第一行和第三行各三个

<style>
        /* 首先两个box交叉轴方向放置,且两个box中间有间距 */
        .container {
            width: 150px;
            height: 150px;
            border: 1px solid black;
            display: flex;
            /* 交叉轴放置 */
            flex-direction: column;
            /* 中间有间距 */
            align-content: space-around;
        }

        .item {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #000;
        }

        /* 给每个box设置弹性布局 */
        .box1,
        .box2 {
            display: flex;
            width: 150px;
            height: 75px;
            justify-content: space-around;
            align-items: center;
        }
    </style>

///结构
<body>
    <div class="container">
        <div class="box1">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="box2">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>
</body>

效果展示:

②第一列和第三列各三个

<style>
        /* 首先两个box交叉轴方向放置,且两个box中间有间距 */
        .container {
            width: 150px;
            height: 150px;
            border: 1px solid black;
            display: flex;
            /* 中间有间距 */
            align-content: space-around;
        }

        .item {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #000;
        }

        /* 给每个box设置弹性布局 */
        .box1,
        .box2 {
            display: flex;
            width: 75px;
            height: 150px;
            flex-direction: column;
            justify-content: space-around;

        }
        .item {
            align-self: center;
        }
    </style>

///结构
<body>
    <div class="container">
        <div class="box1">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="box2">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>
</body>

 效果展示:

 ③麻将的五饼

<style>
        /* 首先两个box交叉轴方向放置,且两个box中间有间距 */
        .container {
            width: 180px;
            height: 180px;
            border: 1px solid black;
            display: flex;
            flex-direction: column;
            align-content: space-around;
        }

        .item {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #000;
        }

        /* 给每个box设置弹性布局 */
        .box1,
        .box2,
        .box3 {
            display: flex;
            width: 180px;
            height: 60px;
            justify-content: space-around;
        }

        .item {
            align-self: center;
        }
    </style>

/结构
<body>
    <div class="container">
        <div class="box1">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="box2">
            <div class="item"></div>
        </div>
        <div class="box3">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>
</body>

效果展示:

六、九项目 

九饼

<style>
        /* 首先两个box交叉轴方向放置,且两个box中间有间距 */
        .container {
            width: 180px;
            height: 180px;
            border: 1px solid black;
            display: flex;
            flex-direction: column;
            align-content: space-around;
        }

        .item {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #000;
        }

        /* 给每个box设置弹性布局 */
        .box1,
        .box2,
        .box3 {
            display: flex;
            width: 180px;
            height: 60px;
            justify-content: space-around;
        }

        .item {
            align-self: center;
        }
 </style>

/结构
<body>
    <div class="container">
        <div class="box1">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="box2">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="box3">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>
</body>

效果展示:

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值