用JavaScript生成一个4行10列的表格,第一列每格的宽度为三倍,在网页居中显示
时间: 2023-12-03 17:42:46 浏览: 77
可以使用以下代码来生成一个4行10列的表格,并应用CSS样式使第一列每格宽度为三倍,并使表格在网页居中显示:
```html
<!DOCTYPE html>
<html>
<head>
<title>Table Example</title>
<style>
table {
margin: 0 auto;
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 10px;
}
td:first-child {
width: 30%;
}
</style>
</head>
<body>
<table>
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 6</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 6</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 6</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 6</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
</table>
</body>
</html>
```
解释一下CSS样式:
- `margin: 0 auto;`使表格在网页中水平居中
- `border-collapse: collapse;`将单元格边框合并
- `td:first-child`用于选中每行的第一个单元格,即第一列
- `width: 30%;`将第一列单元格宽度设置为所有单元格宽度的三倍
阅读全文