html+表格+左侧表头,HTML <thead>表格表头 标签

本文详细介绍了HTML表格表头标签的使用方法,包括其基本语法、常见属性及其用途,并通过一个简单的实例展示了如何利用CSS来美化表格表头,提高表格的可读性和美观度。

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

HTML 表格表头 标签

设置表格表头的组合内容, 内部需要包含一个或者多个 和 或标签,否则没有意义。主要用于CSS 来为这些元素定义样式,从而改变表格的外观。

案例

本案例设置了一行的内容(第一行)为表头,然后通过css样式设置背景颜色为红色。

8d0df7c5c09528ebb68f5cff30b467cd.png

教程学习天数

php7天HTML6天

支持浏览器

95ffd7c42d970fdbc512701bb4a26945.png

3a729b84d94519de1c82c0b6fa62e04e.png

9b32a8cec84269d33d84cad24320dd13.png

1b0c219e477a6675726a96c9791fec2c.png

12496100f50e4260f8154a3be171818f.png

语法

标签打印

如果打印时表格过高,而且又表格的头部和底部出现在每页上,请使用 、

和 联合使用。以下是案例打印效果。

d8309e60d399d2400d0bc6078c1653e2.gif

thead属性属性值描述

right

left

center

justify

charHTML5 不支持。设置 中内容的水平对齐方式。

charcharacterHTML5 不支持。暂无浏览器支持。设置 中内容根据哪个字符来对进行文本对齐。

charoffnumberHTML5 不支持。暂无浏览器支持。设置 中内容的第一个对齐字符的偏移量。

top

middle

bottom

baselineHTML5 不支持。设置 中内容的垂直对齐方式。

全局属性

标签支持HTML 全局属性

事件属性

标签支持HTML 事件属性

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>太阳系行星数据</title> <link href="minimal-table.css" rel="stylesheet"> </head> <body> <h1>太阳系行星数据</h1> <header> <table id="table"> <caption> 太阳系中行星的一些数据。(资料取自<a href="http://nssdc.gsfc.nasa.gov/planetary/factsheet/">NASA 行星数据 - 公制</a>,图片取自<a href="https://www.nasa.gov/multimedia/imagegallery/">NASA 照片库。</a>) </caption> <thead> <td colspan="2"></td> <th scope="col" class="name-column" >名字</th> <th scope="col">图片</th> <th scope="col">质量 (10<sup>24</sup>kg)</th> <th scope="col">直径 (km)</th> <th scope="col">密度 (kg/m<sup>3</sup>)</th> <th scope="col">重力 (m/s<sup>2</sup>)</th> <th scope="col">天长 (小时)</th> <th scope="col">平均温度 (°C)</th> <th scope="col">卫星数量</th> <th scope="col">备注</th> </thead> <tbody> <tr> <th colspan="2" rowspan="4" scope="rowgroup">类地行星</th> <th>水星</th> <td>0.330</td> <td>4879</td> <td>5427</td> <td>3.7</td> <td>4222.6</td> <td>57.9</td> <td>167</td> <td>0</td> <td>距太阳最近</td> </tr> <tr> <th>金星</th> <td>4.87</td> <td>12104</td> <td>5243</td> <td>8.9</td> <td>2802.0</td> <td>108.2</td> <td>464</td> <td>0</td> <td></td> </tr> <tr> <th>地球</th> <td>5.97</td> <td>12756</td> <td>5514</td> <td>9.8</td> <td>24.0</td> <td>149.6</td> <td>15</td> <td>1</td> <td>我们的世界</td> </tr> <tr> <th>火星</th> <td>0.642</td> <td>6792</td> <td>3933</td> <td>3.7</td> <td>24.7</td> <td>227.9</td> <td>-65</td> <td>2</td> <td>红色星球</td> </tr> <tr> <th rowspan="4" scope="rowgroup">类木行星</thead> <th rowspan="2" scope="rowgroup">气巨星</th> <th>木星</th> <td>1898</td> <td>142984</td> <td>1326</td> <td>23.1</td> <td>9.9</td> <td>778.6</td> <td>-110</td> <td>67</td> <td>太阳系最大</td> </tr> <tr> <th>土星</th> <td>568</td> <td>120536</td> <td>687</td> <td>9.1</td> <td>10.7</td> <td>1433.5</td> <td>-140</td> <td>62</td> <td></td> </tr> <tr> <th rowspan="2" scope="rowgroup">冰巨星</th> <th>天王星</th> <td>86.8</td> <td>51118</td> <td>1271</td> <td>8.7</td> <td>17.2</td> <td>2872.5</td> <td>-195</td> <td>27</td> <td></td> </tr> <tr> <th>海王星</th> <td>102</td> <td>49528</td> <td>1631</td> <td>11.0</td> <td>16.1</td> <td>4495.1</td> <td>-200</td> <td>14</td> <td></td> </tr> <tr> <th colspan="2" scope="row">矮行星</th> <th>冥王星</th> <td>0.0146</td> <td>2370</td> <td>2095</td> <td>0.7</td> <td>153.3</td> <td>5906.4</td> <td>-225</td> <td>5</td> <td>2006年降格,但<a href="http://www.usatoday.com/story/tech/2014/10/02/pluto-planet-solar-system/16578959/">尚存争议</a></td> </tr> </tbody> </table> </body> </html> 这个是全部代码。我现在要在“名字”这一列添加一个整体的黑色边框应该怎么弄
08-06
表格内容太多怎么隐藏悬停才展示完整内容<div style="max-height: 900px;overflow: auto;"> <table class="table table-hover table-bordered" style="margin-bottom: 0;"> <thead class="bg-light" style="position: sticky; top: 0; z-index: 1;"> <tr class="head-table"> <th>序号</th> <th>异常标识码</th> <th>操作</th> <th>异常类型</th> <th>工段</th> <th>异常来源</th> <th>异常项目</th> <th>异常等级</th> <th>设备</th> <th>批次号</th> <th>站点</th> <th>工艺流程</th> <th>产品料号</th> <th>异常描述</th> <th>异常CODE类型</th> <th>异常数据</th> <th>异常开始时间</th> <th>是否处理</th> <th>处理人员</th> <th>处理备注</th> <th>结案时间</th> </tr> </thead> <tbody> <tr th:each="data,iterStat : ${page.records}" class="center-table"> <td th:text="${iterStat.count}"></td> <td th:text="${data.ALARMTIMEKEY}"></td> <td th:text="${iterStat.count}"></td> <td th:text="${data.ISSUETYPE}"></td> <td th:text="${data.FACTORYNAME}"></td> <td th:text="${data.ALARMTYPE}"></td> <td th:text="${data.ALARMID}"></td> <td th:text="${data.ALARMLEVEL}"></td> <td th:text="${data.MACHINENAME}"></td> <td th:text="${data.LOTNAME}"></td> <td th:text="${data.PROCESSOPERATIONNAME}"></td> <td th:text="${data.PROCESSFLOWNAME}"></td> <td th:text="${data.PRODUCTSPECNAME}"></td> <td th:text="${data.ALARMCOMMENT}"></td> <td th:text="${data.REASONCODETYPE}"></td> <td th:text="${data.REASONCODE}"></td> <td th:text="${data.START_TIME}"></td> <td th:text="${data.SOLVEFLAG}"></td> <td th:text="${data.SOLVE_USER}"></td> <td th:text="${data.SOLVE_REASON}"></td> <td th:text="${data.END_TIME}"></td> </tr> <!-- 空数据提示 --> <tr th:if="${page.records.isEmpty()}"> <td colspan="21" class="text-center text-muted">暂无数据</td> </tr> </tbody> </table> </div>
03-08
<template> <div class="table-container"> <table class="dynamic-table"> <!-- 表头部分 --> <thead> <tr> <th rowspan="2">Factory</th> <th rowspan="2">YY</th> </tr> <tr> <template v-for="year in yearList" :key="year"> <th colspan="4" class="year-subheader">{{ year }}</th> </template> </tr> <tr> <template v-for="year in yearList" :key="'subheader-'+year"> <th>Category</th> <th>双数%</th> <th>总双数</th> <th>AAA</th> </template> </tr> </thead> <!-- 表格内容 --> <tbody> <template v-for="factory in pageList" :key="factory.fact"> <template v-for="(fc, fcIndex) in factory.fcList" :key="fc"> <tr> <!-- 工厂名称列(只显示在第一行) --> <td v-if="fcIndex === 0" :rowspan="factory.fcList.length" class="factory-cell"> {{ factory.fact }} </td> <!-- YY列 --> <td class="yy-cell">{{ getYYCategory(fc) }}</td> <!-- 动态年份列 --> <template v-for="year in yearList" :key="year"> <td>{{ fc }}</td> <td></td> <!-- 双数%留空 --> <td>{{ getTotalQty(factory.infoList, fc, year) }}</td> <td>{{ getFob(factory.infoList, fc, year) }}</td> </template> </tr> </template> </template> </tbody> </table> </div> </template> <script setup> import { ref, onMounted } from "vue"; import { financeClassifyByYearList } from "@/api/planning/page"; const pageList = ref([]); const yearList = ref([]); // 获取YY分类 function getYYCategory(fc) { const jdCategories = ['JD 聯名款', 'JD 成人鞋', 'JD大童', 'JD 中童', 'JD小童']; const nswCategories = ['NSW 聯名款', 'NSW联名款', 'NSW 联名款', 'NSW 普通款', 'NSW FUEL 聯名款', 'NSW普通款', 'SLT/SP/GEL/FUEL 快速訂單']; const golfCategories = ['GOLF', 'JD GOLF 高尔夫', 'GOLF']; if (jdCategories.includes(fc)) return 'JD'; if (nswCategories.includes(fc)) return 'NSW'; if (golfCategories.includes(fc)) return 'Golf'; return '其他'; } // 获取总双数 function getTotalQty(infoList, fc, year) { if (!infoList) return ''; const item = infoList.find(item => item.financeClassify === fc && String(item.year) === year ); return item ? item.totalQty : ''; } // 获取FOB值 function getFob(infoList, fc, year) { if (!infoList) return ''; const item = infoList.find(item => item.financeClassify === fc && String(item.year) === year ); return item ? item.fob : ''; } // 获取数据 function getList() { financeClassifyByYearList().then((response) => { if (response.code === 200) { pageList.value = response.data; if (pageList.value.length > 0) { yearList.value = pageList.value[0].fyList || []; } } }); } onMounted(() => { getList(); }); </script> <style scoped> .table-container { overflow-x: auto; margin: 20px 0; } .dynamic-table { width: 100%; border-collapse: collapse; font-size: 14px; } .dynamic-table th, .dynamic-table td { border: 1px solid #e0e0e0; padding: 8px 12px; text-align: center; min-width: 80px; } .dynamic-table thead th { background-color: #f5f7fa; font-weight: 600; } .year-header { background-color: #e1f0fa; font-size: 16px; font-weight: bold; } .year-subheader { background-color: #d1e7f7; font-weight: bold; } .factory-cell { background-color: #f0f9eb; font-weight: bold; } .yy-cell { background-color: #fdf6ec; font-weight: bold; } </style> 当前<th>Category</th> <th>双数%</th> <th>总双数</th> <th>AAA</th>开始出现的位置不对,应该从第三列开始,而不是第一列
最新发布
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值