css表头制作

CSS表头制作方法
固定表头(滚动时保持可见)
.table-container {
height: 300px;
overflow-y: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
thead {
position: sticky;
top: 0;
background-color: #f8f9fa;
}
基础样式设计
thead th {
padding: 12px 15px;
text-align: left;
background-color: #3498db;
color: white;
font-weight: bold;
border-bottom: 2px solid #2980b9;
}
悬停效果
thead th:hover {
background-color: #2980b9;
cursor: pointer;
}
斑马条纹表格
tbody tr:nth-child(odd) {
background-color: #f2f2f2;
}
thead th {
background-color: #4CAF50;
color: white;
}
响应式表头
@media screen and (max-width: 600px) {
thead {
display: none;
}
td::before {
content: attr(data-label);
font-weight: bold;
display: inline-block;
width: 120px;
}
}
带排序箭头的表头
th.sortable {
position: relative;
padding-right: 25px;
}
th.sortable::after {
content: "↑↓";
position: absolute;
right: 8px;
opacity: 0.5;
}
th.sort-asc::after {
content: "↑";
opacity: 1;
}
th.sort-desc::after {
content: "↓";
opacity: 1;
}
圆角表头
table {
border-radius: 10px;
overflow: hidden;
}
thead th:first-child {
border-top-left-radius: 10px;
}
thead th:last-child {
border-top-right-radius: 10px;
}







