css制作精美表格
基础表格样式优化
使用 border-collapse 合并边框,避免双边框效果:
table {
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
斑马纹效果
通过 nth-child(even) 实现交替行背景色:
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #e6e6e6;
}
表头突出设计
增加渐变背景和固定高度:
th {
background: linear-gradient(to bottom, #4a90e2, #357ab8);
color: white;
padding: 12px;
font-weight: bold;
}
圆角与阴影效果
为表格添加现代感设计:
table {
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
border-radius: 8px;
overflow: hidden;
}
响应式表格
通过媒体查询实现小屏横向滚动:
@media (max-width: 600px) {
table {
display: block;
overflow-x: auto;
}
}
单元格特殊样式
为重要数据添加高亮:
.highlight {
background-color: #fffacd;
font-weight: bold;
border-left: 3px solid #ffd700;
}
动画交互效果
悬停时平滑过渡:

td {
transition: background-color 0.3s ease;
}





