Data table that stacks into cards on mobile
CSS
/* Cards on small screens; the table markup stays fully semantic. */
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 0.6rem 0.75rem;
text-align: left;
border-bottom: 1px solid #d0d5dd;
}
/* Add data-label="..." to each td; it becomes the row heading on mobile. */
@media (max-width: 36rem) {
thead {
position: absolute;
clip-path: inset(50%);
}
tr {
display: block;
margin-bottom: 1rem;
border: 1px solid #d0d5dd;
border-radius: 0.5rem;
}
td {
display: flex;
justify-content: space-between;
border: 0;
}
td::before {
content: attr(data-label);
font-weight: 600;
}
td:last-child {
border-radius: 0 0 0.5rem 0.5rem;
}
}