给我一个完整的html表格代码
时间: 2024-02-20 11:57:58 浏览: 22
这是一个完整的 HTML 表格代码示例:
```
<!DOCTYPE html>
<html>
<head>
<title>My Table</title>
<style>
table {
border-collapse: collapse;
width: 100%;
font-family: Arial, sans-serif;
font-size: 14px;
}
th, td {
text-align: left;
padding: 8px;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<table>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
<tr>
<td>张三</td>
<td>25</td>
<td>男</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>女</td>
</tr>
<tr>
<td>王五</td>
<td>20</td>
<td>男</td>
</tr>
</table>
</body>
</html>
```
这个代码创建了一个带有样式的表格。`<style>` 标签用于定义表格的样式,包括字体、边框、背景色等。`<tr>` 标签用于定义表格中的行,`<th>` 标签用于定义表头单元格,`<td>` 标签用于定义数据单元格。注意,这里我们使用了伪类选择器 `:nth-child()` 来实现隔行变色。