flex绘制table表格,支持文字自动换行和合并单元格,高度自适应

一、flex布局方法和属性教程

1、参考链接flex布局教程

2、简单理解

01--容器属性

  • flex-direction               左右,上下布局
  • flex-wrap                     是否换行,反向换行
  • flex-flow                      包含flex-direction和flex-wrap 属性
  • justify-content             项目(子元素)是否水平居中
  • align-items                  项目(子元素)是否水平居中
  • align-content               项目(子元素)多根轴线(多列)是否水平居中

03--项目属性

  • order                           子元素排列顺序
  • flex-grow                     子元素放大,默认等比
  • flex-shrink                   子元素缩小,默认等比
  • flex-basis                     可以设定子元素固定大小
  • flex                               flex-grow, flex-shrink 和 flex-basis的简写
  • align-self                      子元素自定义垂直对齐方式

flex绘制table表格,支持文字自动换行,高度自适应(宽度固定)

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <div class="table">
            <div class="flex-box header">
                <div class="flex-cell1 border-rb">
                    <div>序号XXXXXXXXXXXXXXXXXX</div>  
                </div>
                <div class="flex-cell2 border-rb">配件名称xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
                
                <div class="flex-cell3 border-rb">
                    <div class="lossAssessment">
                        <div>
                            <div>定损xxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
                        </div>
                    </div>
                    <div class="lossAssessmentContent">
                        <div class="price border-tr" >价格</div>
                        <div class="count border-t">数量</div>
                    </div>
                </div>
                <div class="flex-cell4 border-b">
                    <div>
                        <div>小计</div>
                    </div>
                    
                </div>
            </div>
            <div class="flex-box tableBody">
                <div class="flex-row">
                    <div class="flex-cell1 border-rb">序号XXXXXXXXXXXXXXXXXXXX</div>
                    <div class="flex-cell2 border-rb">配件名称</div>
                    <div class="flex-cell3 border-rb">价格</div>
                    <div class="flex-cell4 border-rb">数量</div>
                    <div class="flex-cell5 border-rb">小计</div>
                </div>
                <div class="flex-row">
                    <div class="flex-cell1 border-rb">序号</div>
                    <div class="flex-cell2 border-rb">配件名称</div>
                    <div class="flex-cell3 border-rb">价格</div>
                    <div class="flex-cell4 border-rb">数量</div>
                    <div class="flex-cell5 border-rb">小计</div>
                </div>
                <div class="flex-row">
                    <div class="flex-cell1 border-rb">序号</div>
                    <div class="flex-cell2 border-rb">配件名称</div>
                    <div class="flex-cell3 border-rb">价格</div>
                    <div class="flex-cell4 border-rb">数量xxxxxxxxxxxxxxxxxxxxxx</div>
                    <div class="flex-cell5 border-rb">
                        小计
                    </div>
                </div>
                
            </div>
            
          
        </div>
        <style lang="scss">
            .table{
                width: 300px;
                border: 1px solid #666;
                word-wrap: break-word;
                margin: 0 auto;
                .header{
                    /* width: 300px; */
                    display: flex;
                    flex-direction: row;
                    flex-wrap: nowrap;
                    color: #666;
                    font-size: 14px;
                    text-align: center;
                    box-sizing: border-box;
                    .flex-cell1{
                        width: 50px;
                    }
                    
                    .flex-cell2{
                        width: 100px;
                    }
                    .flex-cell3{
                        width: 100px;
                        display: flex;
                        flex-direction: row;
                        flex-wrap: wrap;

                        .lossAssessment{
                            width: 100%;
                        }
                        .lossAssessmentContent{
                            display: flex;
                            flex-direction: row;
                            flex-wrap: nowrap;
                            .price{
                                width: 50px;
                            }
                            .count{
                                width: 50px;
                            }
                            
                        }
                    }
                    .flex-cell4{
                        width: 50px;
                    }
                }
                .tableBody{
                    .flex-row{
                        display: flex;
                        flex-direction: row;
                        flex-wrap: nowrap;
                        color: #666;
                        font-size: 14px;
                        text-align: center;
                        box-sizing: border-box;
                        .flex-cell1{
                            width: 50px;
                        }
                        .flex-cell2{
                            width: 100px;
                        }
                        .flex-cell3{
                            width: 50px;
                        }
                        .flex-cell4{
                            width: 50px;
                        }
                        .flex-cell5{
                            width: 50px;
                        }
                        .border-rb:last-child{
                            border-right: none !important;
                        }
                    }

                    .flex-row:last-child{
                        .border-rb{
                            border-bottom: none !important;
                        }
                    }

                    

                    
                    
                   
                }

                .border-t{
                    border-top: 1px solid #666;
                    box-sizing: border-box;
                }

                .border-tr{
                    border-right: 1px solid #666;
                    border-top: 1px solid #666;
                    box-sizing: border-box;
                }
                .border-rb{
                    border-right: 1px solid #666;
                    border-bottom: 1px solid #666;
                    box-sizing: border-box;
                }
                .border-b{
                    border-bottom: 1px solid #666;
                    box-sizing: border-box;
                }
                

            }
            
        </style>    
    </body>
</html>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值