css 设置table 单元格长度的问题

10 篇文章 0 订阅

见代码:
在这里插入图片描述

.table-fixed-box {
    position: relative;
}

.fixed__header {
    position: absolute;
    top: -38px;
    width: 100%;
    left: 0;
    margin: 0;
    overflow: hidden;
    z-index: 102;
    background: white;
}

.row-table {
    width: 100%;
    text-align: left;
    table-layout: fixed
}

.row-table thead {
    color: #97a8b8;
}

.row-table thead th {
    border-bottom: 1px solid #eee;
    line-height: 38px;
    text-align: left;
    position: relative;
}

.fixed__table {
    display: block;
    margin-top: 38px;
    width: 100%;
    min-height: 200px;
    max-height: 580px;
    overflow-y: auto;
}
.row-table tbody tr{
    width: 100%;
    border-bottom: 1px solid #eee;
}
.row-table tbody td {
    position: relative;
    line-height: 30px;
    text-align: left;
    font-size: 12px;
}

<div class="table-fixed-box">
    <div class="fixed__header">
        <table class="row-table" v-show="table !== ''">
            <colgroup>
                <col :width="(Number(index)+1) == table.title.length?' ':item.minWidth" v-for="(item,index) in table.title" :key="index">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th :width="(Number(index)+1) == table.title.length?' ':item.minWidth" v-for="(item,index) in table.title" :key="index">{{selectTitle(item.title)}}</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <div class="fixed__table">
        <table class="row-table" v-show="table !== ''">
            <colgroup>
                <col :width="(Number(index)+1) == table.title.length?' ':item.minWidth" v-for="(item,index) in table.title" :key="index">
                <col>
            </colgroup>
            <thead>
            <tr style="display: none;">
                <th :width="(Number(index)+1) == table.title.length?' ':item.minWidth" v-for="(item,index) in table.title" :key="index">{{selectTitle(item.title)}}</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(item,index) in table.data" :key="index">
                <td :width="(Number(Index)+1) == table.title.length?' ':items.minWidth" v-for="(items,Index) in table.title" :key="Index">{{item[items.field]}}</td>
                <td></td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

width三目运算的作用是让最后一个td的宽度保持自适应,这样表格就不会撑不满100%的宽度
两个位置同样如此
thead、tbody中也是一样都要多留一个
如果不留的话就是这样的效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值