自求 2022-08-10 14:07 采纳率: 100%
浏览 79
已结题

flex布局,盒子大小不固定,换行出现问题

我想要达到的结果

在一个div中,有若干个盒子。如何用flex布局达到下面的效果。

<div class="div">
        <div class="div1">1</div>
        <div class="div2">2</div>
        <div class="div3">3</div>
        <div class="div4">4</div>
        <div class="div5">5</div>
        <div class="div6">6</div>
        <div class="div7">7</div>
        <div class="div8">8</div>
        <div class="div9">9</div>
    </div>

img

  • 写回答

3条回答 默认 最新

  • 雾里桃花 2022-08-10 14:30
    关注

    img

    
    <!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>
                * {
                    margin: 0;
                }
                
                .radius{
                    border-radius: 8px;
                }
                
                .bg-orange{
                    background: orange;
                }
                
                .bg-green {
                    background: yellowgreen;
                }
                
                .head {
                    height: 200px;
                    width: 100%;
                    display: flex;
                }
                
                .head .left {
                    width: 40%;
                    height: 100%;
                    margin-right: 10px;
                }
                
                .head .right {
                    display: flex;
                    flex: 1;
                    flex-direction: column;
                }
                
                .head .right .r-top {
                    height: 50%;
                    width: 100%;
                }
                
                .head .right .r-bottom {
                    height: 50%;
                    margin-top: 10px;
                    display: flex;
                    width: 100%;
                }
                
                .head .right .r-bottom .item {
                    flex: 1;
                }
                
                .head .right .r-bottom .item:first-child {
                    margin-right: 10px;
                }
                
                
                .body {
                    width: 100%;
                    height: 100px;
                    display: flex;
                    margin-top: 10px;
                }
                
                .body .item {
                    flex: 1;
                    margin-right: 10px;
                }
                
                .body .item:last-child {
                    margin: 0;
                }
                
                .foot {
                    width: 100%;
                    height: 100px;
                    display: flex;
                    margin-top: 10px;
                }
                
                .foot .item {
                    flex: 1;
                    margin-right: 10px;
                }
                
                .foot .item:last-child {
                    margin: 0;
                }
                
    
            </style>
        </head>
        <body>
            <div class="main">
                <div class="head">
                    <div class='left bg-orange radius'></div>
                    <div class='right'>
                        <div class='r-top bg-green radius'></div>
                        <div class='r-bottom'>
                            <div class='item bg-green radius'></div>
                            <div class='item bg-green radius'></div>
                        </div>
                    </div>
                </div>
                
                <div class='body'>
                    <div class='item radius bg-orange'></div>
                    <div class='item radius bg-orange'></div>
                    <div class='item radius bg-orange'></div>
                </div>
                
                <div class='foot'>
                    <div class='item radius bg-orange'></div>
                    <div class='item radius bg-orange'></div>
                </div>
            </div>
        </body>
    </html>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 8月18日
  • 已采纳回答 8月10日
  • 修改了问题 8月10日
  • 创建了问题 8月10日

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭