CSS表格边框代码主要用于设置HTML表格的边框样式。以下是一些基础概念和相关代码示例:
以下是一个简单的HTML表格,并使用CSS设置边框样式的示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Table Border Example</title>
<style>
table {
border-collapse: collapse; /* 合并边框 */
width: 100%;
}
th, td {
border: 1px solid black; /* 设置单元格边框 */
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
</tbody>
</table>
</body>
</html>
border: 1px solid black;
。border-collapse: collapse;
属性可以合并单元格之间的边框。border-color: red;
。通过以上示例和解释,你应该能够理解如何使用CSS设置表格边框,并解决一些常见问题。
领取专属 10元无门槛券
手把手带您无忧上云