帮我写一个html中精美的table表格并且带有美化样式
时间: 2023-10-20 15:25:15 浏览: 50
好的,以下是一个带样式的HTML表格模板:
```html
<style>
table {
border-collapse: collapse;
width: 100%;
font-family: Arial, sans-serif;
}
th, td {
text-align: left;
padding: 8px;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
@media screen and (max-width: 600px) {
table, thead, tbody, th, td, tr {
display: block;
}
th {
text-align: center;
}
.table-header {
display: none;
}
}
</style>
<table>
<thead class="table-header">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>城市</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>25</td>
<td>男</td>
<td>北京</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>女</td>
<td>上海</td>
</tr>
<tr>
<td>王五</td>
<td>28</td>
<td>男</td>
<td>广州</td>
</tr>
</tbody>
</table>
```
这个表格使用了CSS样式,包括表格的边框、表头背景色、偶数行背景色等。同时,还使用了媒体查询,使得在屏幕宽度小于600px时,表格会自动变为垂直布局。你可以根据自己的需求修改样式。