表格制作css
基础表格样式设计
使用CSS的border属性为表格添加边框,确保单元格之间无间隙
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
斑马纹效果实现
通过:nth-child()选择器实现交替行颜色
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #e9e9e9;
}
表头样式优化
突出显示表头并固定位置(适用于长表格)

th {
background-color: #4CAF50;
color: white;
position: sticky;
top: 0;
}
响应式表格处理
添加水平滚动条应对小屏幕设备
@media screen and (max-width: 600px) {
table {
display: block;
overflow-x: auto;
}
}
高级交互效果
点击排序功能需配合JavaScript实现

th.sortable {
cursor: pointer;
background-image: url('data:image/svg+xml;utf8,<svg ...>');
background-repeat: no-repeat;
background-position: right center;
}
单元格特殊样式
合并单元格的样式控制
td.merged {
text-align: center;
font-weight: bold;
background-color: #e1f5fe;
}
表格间距与对齐
精细控制表格元素间距
table {
margin: 20px 0;
box-shadow: 0 2px 3px rgba(0,0,0,0.1);
}
td {
vertical-align: middle;
}





