
<head>
<title></title>
<style type="text/css">
table
{
border-collapse: collapse;
margin: 0 auto;
text-align: center;
}
table td, table th
{
border: 1px solid #cad9ea;
color: #666;
height: 30px;
}
table thead th
{
background-color: #CCE8EB;
width: 100px;
}
table tr:nth-child(odd)
{
background: #fff;
}
table tr:nth-child(even)
{
background: #F5FAFA;
}
</style>
</head>
<body>
<table width="90%" class="table">
<caption>
<h2>
车间能源消耗比例</h2>
</caption>
<thead>
<tr>
<th>
车间
</th>
<th>
产量
</th>
<th>
电量
</th>
<th>
单耗
</th>
</tr>
</thead>
<tr>
<td>
109
</td>
<td>
13
</td>
<td>
1.34
</td>
<td>
213
</td>
</tr>
<tr>
<td>
109
</td>
<td>
13
</td>
<td>
1.34
</td>
<td>
213
</td>
</tr>
<tr>
<td>
109
</td>
<td>
13
</td>
<td>
1.34
</td>
<td>
213
</td>
</tr>
<tr>
<td>
109
</td>
<td>
13
</td>
<td>
1.34
</td>
<td>
213
</td>
</tr>
<tr>
<td>
109
</td>
<td>
13
</td>
<td>
1.34
</td>
<td>
213
</td>
</tr>
<tr>
<td>
109
</td>
<td>
13
</td>
<td>
1.34
</td>
<td>
213
</td>
</tr>
</table>
</body>
</html>
table 表格怎么做出整齐的边框效果?
核心是给 table 设置 border-collapse: collapse,让单元格边框合并成一条线,再给 td、th 统一加 1px 边框。这样表格不会出现边框重叠或空隙,整体更利落,适合展示数据类内容。
表格隔行变色怎么写最省事?
可以直接用 CSS 的 :nth-child(odd) 和 :nth-child(even) 给 tr 设置不同背景色。这样不用手动给每一行加 class,就能实现斑马纹效果,长表格更容易看行,阅读体验会明显提升。
表头和正文样式分开设置有什么好处?
把 thead th 单独设背景色、宽度和字体颜色,能让表头和数据区层次更清楚。配合居中对齐与统一行高,表格会更规整,尤其适合报表、统计表这类需要快速浏览的页面。





