css利用flex布局画骰子的六个面

主要是利用flex的一些特性来写的,掌握好flex基础,写出筛子的几个页面不是问题。
推荐去我写的一个博客中有flex的小练习 线上练习flex布局

html

<body>
    <div class="shaizi">
        <div class="top">
            <div class="box1 box">
                <span class="item"></span>
            </div>
            <div class="box2 box">
                <span class="item"></span>
                <span class="item"></span>
            </div>
            <div class="box3 box">
                <span class="item"></span>
                <span class="item"></span>
                <span class="item"></span>
            </div>
        </div>
        <div class="bottom">
            <div class="box4 box">
                <div class="box4_top">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
                <div class="box4_buttom">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
            </div>
            <div class="box5 box">
                <div class="box5_top">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
                <div class="box5_center">
                    <span class="item"></span>
                </div>
                <div class="box5_buttom">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
            </div>
            <div class="box6 box">
                <div class="box6_top">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
                <div class="box6_center">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
                <div class="box6_buttom">
                    <span class="item"></span>
                    <span class="item"></span>
                </div>
            </div>
        </div>
    </div>
</body>

css

<style>
    .shaizi {
        width: 1400px;
        height: 600px;
        margin: auto;
        border: 2px solid #ddd;
        border-radius: 10px;
        padding: 20px;
        display: flex;
        flex-wrap: wrap;
        /* flex-direction: column;; */
    }
    .item {
        display: block;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background-color: #666;
    }
    .box{
        width: 200px;
        height: 200px;
        border: 2px solid #ccc;
        border-radius: 10px;
        padding: 20px;
        display: flex;
    }
    .top {
        display: flex;
        width: 1400px;
        justify-content: space-around;
    }
    .bottom{
        display: flex;
        width: 1400px;
        justify-content: space-around;
    }
    .box1 {
        justify-content: center;
        align-items: center;
    }
    .box2 {
        justify-content: space-between;
        align-items: center;
    }
    .box3 {
        justify-content: space-between;
        /* 两端对齐 */
    }
    .box3 .item:nth-child(2) {
        align-self: center;
        /* 上下左右居中对齐 */
    }
    .box3 .item:nth-child(3) {
        align-self: flex-end;
        /* 尾对齐 */
    }
    .box4 {
         flex-direction: column;
         justify-content: space-between;
    }
    .box4_top{
        width: 200px;
        height: 100px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .box4_buttom{
        width: 200px;
        height: 100px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .box5{
        flex-direction: column;
        justify-content: space-between;
    }
    .box5_top{
        display: flex;
        justify-content: space-between;
    }
    .box5_center{
        display: flex;
        justify-content: center;
    }
    .box5_buttom{
        display: flex;
        justify-content: space-between;
    }
    .box6{
        flex-direction: column;
        justify-content: space-between;
    }
    .box6_top{
        display: flex;
        justify-content: space-between;
    }
    .box6_center{
        display: flex;
        justify-content: space-between;
    }
    .box6_buttom{
        display: flex;
        justify-content: space-between;
    }
</style>

效果

posted @ 2020-09-24 09:55  爱喝可乐的靓仔  阅读(1555)  评论(0编辑  收藏  举报