表格tb制作css
使用 CSS 美化 HTML 表格
为表格添加 CSS 样式可以提升视觉效果和用户体验。以下是一些常见的 CSS 属性和方法,用于美化 HTML 表格。
基础表格结构
<table class="tb">
<thead>
<tr>
<th>标题1</th>
<th>标题2</th>
</tr>
</thead>
<tbody>
<tr>
<td>内容1</td>
<td>内容2</td>
</tr>
</tbody>
</table>
常用 CSS 样式
.tb {
width: 100%;
border-collapse: collapse; /* 合并边框 */
margin: 20px 0;
font-family: Arial, sans-serif;
}
.tb th, .tb td {
padding: 12px 15px;
text-align: left;
border: 1px solid #ddd;
}
.tb th {
background-color: #f4f4f4;
font-weight: bold;
}
.tb tr:nth-child(even) {
background-color: #f9f9f9;
}
.tb tr:hover {
background-color: #f1f1f1;
}
高级样式选项
.tb {
box-shadow: 0 2px 3px rgba(0,0,0,0.1);
}
.tb thead {
position: sticky;
top: 0;
}
.tb td {
transition: background-color 0.3s ease;
}
响应式表格设计
对于移动设备,可以添加以下样式:
@media screen and (max-width: 600px) {
.tb {
display: block;
overflow-x: auto;
}
}
边框样式定制
.tb {
border-radius: 5px;
overflow: hidden;
}
.tb th:first-child {
border-top-left-radius: 5px;
}
.tb th:last-child {
border-top-right-radius: 5px;
}
这些 CSS 规则可以根据具体需求进行调整和组合,创建出各种不同风格的表格样式。







