自求 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日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改