设计思路
- 使用CSS伪元素实现整行删除线
- 添加渐变背景和阴影增强视觉效果
- 使用不同颜色区分删除线状态
最终实现代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>表格行删除线效果</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
color: #333;
}
.container {
max-width: 900px;
width: 100%;
background: white;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
padding: 30px;
margin-top: 20px;
}
h1 {
text-align: center;
margin-bottom: 10px;
color: #2c3e50;
font-weight: 600;
}
.subtitle {
text-align: center;
color: #7f8c8d;
margin-bottom: 30px;
font-size: 1.1rem;
}
.table-container {
overflow-x: auto;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}
table {
width: 100%;
border-collapse: collapse;
min-width: 600px;
}
th {
background: #3498db;
color: white;
text-align: left;
padding: 16px 15px;
font-weight: 600;
}
th:first-child {
border-top-left-radius: 8px;
}
th:last-child {
border-top-right-radius: 8px;
}
td {
padding: 14px 15px;
border-bottom: 1px solid #eaeaea;
position: relative;
}
/* 删除线效果 */
.strikethrough-row {
position: relative;
}
.strikethrough-row::after {
content: "";
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 2px;
background: linear-gradient(90deg, transparent 0%, #e74c3c 20%, #e74c3c 80%, transparent 100%);
transform: translateY(-50%);
z-index: 1;
pointer-events: none;
}
/* 不同颜色的删除线 */
.strikethrough-row.red::after {
background: linear-gradient(90deg, transparent 0%, #e74c3c 20%, #e74c3c 80%, transparent 100%);
}
.strikethrough-row.blue::after {
background: linear-gradient(90deg, transparent 0%, #3498db 20%, #3498db 80%, transparent 100%);
}
.strikethrough-row.green::after {
background: linear-gradient(90deg, transparent 0%, #2ecc71 20%, #2ecc71 80%, transparent 100%);
}
.strikethrough-row.orange::after {
background: linear-gradient(90deg, transparent 0%, #e67e22 20%, #e67e22 80%, transparent 100%);
}
/* 行悬停效果 */
tr:not(.strikethrough-row):hover {
background-color: #f8f9fa;
}
.strikethrough-row:hover {
background-color: rgba(231, 76, 60, 0.05);
}
/* 状态标签 */
.status {
display: inline-block;
padding: 4px 10px;
border-radius: 20px;
font-size: 0.85rem;
font-weight: 500;
}
.status.completed {
background-color: #e8f6f3;
color: #27ae60;
}
.status.cancelled {
background-color: #fdedec;
color: #e74c3c;
}
.status.pending {
background-color: #fef9e7;
color: #f39c12;
}
/* 响应式设计 */
@media (max-width: 768px) {
.container {
padding: 20px 15px;
}
th, td {
padding: 12px 10px;
}
}
.note {
margin-top: 25px;
padding: 15px;
background-color: #f8f9fa;
border-left: 4px solid #3498db;
border-radius: 4px;
font-size: 0.95rem;
}
</style>
</head>
<body>
<div class="container">
<h1>表格行删除线效果</h1>
<p class="subtitle">使用CSS伪元素实现整行删除线</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>任务名称</th>
<th>负责人</th>
<th>截止日期</th>
<th>状态</th>
</tr>
</thead>
<tbody>
<tr class="strikethrough-row red">
<td>项目需求分析</td>
<td>张三</td>
<td>2023-10-15</td>
<td><span class="status completed">已完成</span></td>
</tr>
<tr>
<td>UI/UX设计</td>
<td>李四</td>
<td>2023-11-05</td>
<td><span class="status pending">进行中</span></td>
</tr>
<tr class="strikethrough-row blue">
<td>前端开发</td>
<td>王五</td>
<td>2023-09-30</td>
<td><span class="status completed">已完成</span></td>
</tr>
<tr>
<td>后端API开发</td>
<td>赵六</td>
<td>2023-12-10</td>
<td><span class="status pending">进行中</span></td>
</tr>
<tr class="strikethrough-row orange">
<td>测试计划制定</td>
<td>钱七</td>
<td>2023-08-20</td>
<td><span class="status cancelled">已取消</span></td>
</tr>
<tr>
<td>用户手册编写</td>
<td>孙八</td>
<td>2023-12-25</td>
<td><span class="status pending">进行中</span></td>
</tr>
<tr class="strikethrough-row green">
<td>项目启动会议</td>
<td>周九</td>
<td>2023-07-10</td>
<td><span class="status completed">已完成</span></td>
</tr>
</tbody>
</table>
</div>
<div class="note">
<p><strong>说明:</strong> 带有删除线的行表示已完成或已取消的任务。删除线使用CSS伪元素实现,无需JavaScript控制,源码由www.02405.com网站设计。</p>
</div>
</div>
</body>
</html>