编写一个好看的表格样式
时间: 2023-12-31 22:32:27 浏览: 27
当涉及到表格样式时,美观是一个主观的概念,因为每个人对于好看的定义可能不同。不过,我可以为你提供一个简单的表格样式示例,你可以根据自己的需求进行修改和扩展。
HTML部分:
```html
<table class="custom-table">
<thead>
<tr>
<th>标题1</th>
<th>标题2</th>
<th>标题3</th>
</tr>
</thead>
<tbody>
<tr>
<td>数据1</td>
<td>数据2</td>
<td>数据3</td>
</tr>
<tr>
<td>数据4</td>
<td>数据5</td>
<td>数据6</td>
</tr>
</tbody>
</table>
```
CSS部分:
```css
.custom-table {
width: 100%;
border-collapse: collapse;
}
.custom-table th,
.custom-table td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.custom-table th {
background-color: #f2f2f2;
}
.custom-table tbody tr:nth-child(even) {
background-color: #f9f9f9;
}
.custom-table tbody tr:hover {
background-color: #eaeaea;
}
```
这段代码为你提供了一个简单的表格样式,包括表头背景色、边框样式、交替行背景色以及鼠标悬停时的背景色效果。你可以根据需要自定义颜色、字体样式等来使表格更符合你的要求。
记得将上面的CSS代码放在`<style>`标签内或者添加到你的CSS文件中。如果需要更多样式,你可以在CSS中添加其他属性和选择器来进一步定制表格样式。
希望这个简单的示例能对你有所帮助!如果还有其他问题,请随时提问。