table表格嵌套,边框重叠变粗的解决

本文介绍了一种解决HTML中嵌套table元素时出现的边框重复问题的方法。通过设置外层table的样式属性为border-collapse: collapse;,并设置内层table的样式属性为border-collapse: collapse; 和 border-width: 0px; border-style: hidden; 来避免边框重复显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在外层table与内层table嵌套,内外表格都需边框时,设置“border=1”,但边框会重复,造成某些地方边框粗,有些地方边框细,如图

 

 

解决方法

 

1、外表格样式


<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse;”>


2、内表格样式
 

<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse;border-width:0px; border-style:hidden;">

<template> <table class="data-table"> <!-- 表头行 --> <tr> <th class="label">项目</th> <th v-for="(header, index) in headers" :key="index">{{ header }}</th> </tr> <!-- 数据行 --> <tr v-for="(row, rowIndex) in tableRows" :key="rowIndex"> <td class="label">{{ row.label }}</td> <!-- 普通行 --> <template v-if="row.label !== '便'"> <td v-for="(col, colIndex) in row.columns" :key="colIndex"> {{ col.value }} </td> </template> <!-- "便"行特殊处理 --> <template v-else> <td v-for="(col, colIndex) in row.columns" :key="colIndex" class="nested-cell"> <table class="inner-table"> <tr> <td v-for="(subValue, subIndex) in col.values" :key="subIndex"> {{ subValue }} </td> </tr> </table> </td> </template> </tr> </table> </template> <script setup> import { ref, reactive } from 'vue'; // 表头数据 const headers = ref(['周一', '周二', '周三', '周四', '周五']); // 表格数据结构 const tableRows = reactive([ { label: '日期', columns: Array(5).fill({ value: '1998-10-30' }) }, { label: '天气', columns: Array(5).fill({ value: '晴' }) }, { label: '气温', columns: Array(5).fill({ value: '38℃' }) }, { label: '便', columns: Array(5).fill({ values: ['1', '2', '3'] // 每个单元格包含3个子值 }) } ]); // 动态更新示例 setTimeout(() => { // 更新日期行的第二列 tableRows[0].columns[1].value = '2023-07-21'; // 更新便行第三列的值 tableRows[3].columns[2].values = ['4', '5', '6']; }, 2000); </script> <style scoped> .data-table { width: 100%; border-collapse: collapse; margin: 20px 0; } .data-table th, .data-table td { border: 1px solid #ccc; padding: 10px; text-align: center; } .label { font-weight: bold; background-color: #f5f5f5; width: 15%; } /* 嵌套表格样式 */ .nested-cell { padding: 0 !important; /* 移除外部单元格的内边距 */ } .inner-table { width: 100%; height: 100%; border-collapse: collapse; } .inner-table td { border: 1px solid #aaa; padding: 5px; width: 33.33%; /* 三等分宽度 */ } </style> 我想让拆分的表格线统一
最新发布
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是刘奇奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值