html表格代码
时间: 2023-06-30 19:20:01 浏览: 70
下面是一个简单的 HTML 表格代码示例:
```
<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>
</table>
```
这个代码创建了一个带有表头和两行数据的表格。 `<table>` 标签用于定义表格, `<tr>` 标签用于定义表格中的行, `<th>` 标签用于定义表头单元格, `<td>` 标签用于定义数据单元格。
相关问题
html整齐表格代码
以下是一个简单的HTML表格代码示例,可用于创建整齐的表格:
```html
<table>
<thead>
<tr>
<th>列1</th>
<th>列2</th>
<th>列3</th>
</tr>
</thead>
<tbody>
<tr>
<td>行1,列1</td>
<td>行1,列2</td>
<td>行1,列3</td>
</tr>
<tr>
<td>行2,列1</td>
<td>行2,列2</td>
<td>行2,列3</td>
</tr>
</tbody>
</table>
```
该代码将创建一个包含3列和2行的表格,其中第一行是表头,第二行是表格主体中的数据行。您可以根据需要添加更多行和列,并使用CSS样式表来自定义表格的外观。
给我一个完整的html表格代码
这是一个完整的 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()` 来实现隔行变色。