css制作biaoge
使用CSS制作表格
在HTML中创建表格通常使用<table>标签,结合CSS可以美化表格样式。以下是一个完整的示例:
HTML结构
<table class="styled-table">
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>城市</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>25</td>
<td>北京</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>上海</td>
</tr>
</tbody>
</table>
CSS样式

.styled-table {
width: 100%;
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
.styled-table thead tr {
background-color: #009879;
color: #ffffff;
text-align: left;
}
.styled-table th,
.styled-table td {
padding: 12px 15px;
}
.styled-table tbody tr {
border-bottom: 1px solid #dddddd;
}
.styled-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.styled-table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
.styled-table tbody tr:hover {
background-color: #f1f1f1;
}
响应式表格设计
对于移动设备,可以使用以下方法使表格响应式:
@media screen and (max-width: 600px) {
.styled-table {
border: 0;
}
.styled-table thead {
display: none;
}
.styled-table tr {
margin-bottom: 10px;
display: block;
border-bottom: 2px solid #ddd;
}
.styled-table td {
display: block;
text-align: right;
font-size: 13px;
border-bottom: 1px dotted #ccc;
}
.styled-table td:before {
content: attr(data-label);
float: left;
font-weight: bold;
}
}
表格边框样式
设置不同的边框样式可以增强表格可读性:

.styled-table {
border: 1px solid #ddd;
}
.styled-table th,
.styled-table td {
border: 1px solid #ddd;
}
/* 圆角边框 */
.styled-table {
border-radius: 5px;
overflow: hidden;
}
表格颜色方案
使用CSS变量可以轻松切换表格主题:
:root {
--primary-color: #4285f4;
--secondary-color: #f1f8fe;
}
.styled-table thead tr {
background-color: var(--primary-color);
}
.styled-table tbody tr:nth-of-type(even) {
background-color: var(--secondary-color);
}
表格动画效果
添加悬停动画提升用户体验:
.styled-table tbody tr {
transition: all 0.3s ease;
}
.styled-table tbody tr:hover {
transform: scale(1.02);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}






