制作表格css样式
基础表格样式设计
设置表格的基本布局和边框样式,使表格结构清晰可见:
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
表头样式优化
增强表头的视觉层次感,通过背景色和字体变化突出显示:
th {
background-color: #f2f2f2;
font-weight: bold;
color: #333;
}
斑马纹效果
添加隔行变色效果,提高表格数据的可读性:
tr:nth-child(even) {
background-color: #f9f9f9;
}
悬停高亮效果
为表格行添加悬停反馈,提升交互体验:
tr:hover {
background-color: #f1f1f1;
}
响应式表格设计
针对移动设备优化表格显示,添加水平滚动功能:
@media screen and (max-width: 600px) {
table {
display: block;
overflow-x: auto;
}
}
高级样式定制
添加圆角边框和阴影效果,创建现代化表格外观:
table {
box-shadow: 0 2px 3px rgba(0,0,0,0.1);
border-radius: 5px;
overflow: hidden;
}
th:first-child {
border-top-left-radius: 5px;
}
th:last-child {
border-top-right-radius: 5px;
}
单元格对齐方式
根据不同数据类型设置对齐方式,优化视觉效果:
.number-cell {
text-align: right;
}
.center-cell {
text-align: center;
}
边框样式调整
自定义边框样式,创建更精致的视觉效果:
td {
border-bottom: 1px solid #e0e0e0;
}
tr:last-child td {
border-bottom: none;
}






