css制作表格模板

CSS 表格模板示例
以下是一个使用 CSS 制作的表格模板,包含基础样式、响应式设计和交互效果。

基础表格样式
<table class="styled-table">
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>职业</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>25</td>
<td>设计师</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>工程师</td>
</tr>
</tbody>
</table>
.styled-table {
width: 100%;
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
.styled-table thead tr {
background-color: #009879;
color: #ffffff;
text-align: left;
}
.styled-table th,
.styled-table td {
padding: 12px 15px;
}
.styled-table tbody tr {
border-bottom: 1px solid #dddddd;
}
.styled-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.styled-table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
.styled-table tbody tr:hover {
background-color: #f1f1f1;
cursor: pointer;
}
响应式表格设计
当屏幕尺寸较小时,表格可以水平滚动:
.table-container {
overflow-x: auto;
}
@media screen and (max-width: 600px) {
.styled-table {
font-size: 0.8em;
}
.styled-table th,
.styled-table td {
padding: 8px 10px;
}
}
斑马条纹效果
.styled-table tbody tr:nth-child(odd) {
background-color: #f9f9f9;
}
.styled-table tbody tr:nth-child(even) {
background-color: #ffffff;
}
高亮当前行
.styled-table tbody tr.active-row {
font-weight: bold;
color: #009879;
}
边框样式调整
.styled-table {
border: 1px solid #ddd;
}
.styled-table th,
.styled-table td {
border: 1px solid #ddd;
}
圆角表格
.styled-table {
border-radius: 5px;
overflow: hidden;
}
表格标题样式
.caption-style {
caption-side: bottom;
text-align: right;
font-style: italic;
padding: 10px;
color: #666;
}
这些 CSS 样式可以根据需要组合使用,创建出各种不同风格的表格。通过调整颜色、间距、边框等属性,可以轻松定制表格的外观。






