You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>炫酷表格</title>
<style>
/* 表格样式 */
table {
width: 100%;
border-collapse: collapse;
font-family: Arial, sans-serif;
}
/* 表头样式 */
th {
background-color: #4CAF50; /* 绿色背景 */
color: white; /* 白色文字 */
padding: 10px; /* 内边距 */
text-align: left; /* 文字左对齐 */
}
/* 表格行样式 */
tr:nth-child(even) {
background-color: #f2f2f2; /* 偶数行灰色背景 */
}
/* 单元格样式 */
td {
padding: 10px; /* 内边距 */
text-align: left; /* 文字左对齐 */
border-bottom: 1px solid #ddd; /* 底边框 */
}
/* 炫酷效果:渐变背景色 */
tr:nth-child(odd) {
background: linear-gradient(to right, #ff9966, #ff5e62); /* 奇数行渐变背景 */
}
/* 响应式表格 */
@media screen and (max-width: 600px) {
table, thead, tbody, th, td, tr {
display: block;
}
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr {
margin: 0 0 1rem 0;
}
td {
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}
td:before {
position: absolute;
top: 0.6rem;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
content: attr(data-column);
}
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>30</td>
<td>北京</td>
</tr>
<tr>
<td>李四</td>
<td>25</td>
<td>上海</td>
</tr>
<tr>
<td>王五</td>
<td>35</td>
<td>深圳</td>
</tr>
</tbody>
</table>
</body>
</html>