欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > 将element-plus table背景改成透明色

将element-plus table背景改成透明色

2025/8/10 6:02:51 来源:https://blog.csdn.net/2401_89806660/article/details/148882517  浏览:    关键词:将element-plus table背景改成透明色

方法一:全局修改(推荐)

/* 全局透明表格样式 */
.el-table,
.el-table__header-wrapper,
.el-table__body-wrapper,
.el-table__row {background-color: transparent !important;
}/* 可选:自定义表头和斑马纹行的透明度 */
.el-table__header th {background-color: rgba(245, 247, 250, 0.5) !important;
}.el-table__row--striped td {background-color: rgba(249, 250, 251, 0.3) !important;
}.el-table__row:hover td {background-color: rgba(230, 247, 255, 0.5) !important;
}

方法二:局部修改(按需使用)

/* 局部透明表格样式 */
.transparent-table .el-table,
.transparent-table .el-table__header-wrapper,
.transparent-table .el-table__body-wrapper,
.transparent-table .el-table__row {background-color: transparent !important;
}/* 可选样式... */

模板中使用

<div class="transparent-table"><el-table :data="tableData"><!-- 表格内容 --></el-table>
</div>

方法三:使用 CSS 变量(更灵活)

/* 自定义表格透明度 */
:root {--el-table-bg-color: transparent;--el-table-header-bg-color: rgba(245, 247, 250, 0.5);--el-table-row-hover-bg-color: rgba(230, 247, 255, 0.5);
}

注意事项

  1. 层级问题:如果表格在卡片或其他容器内,可能需要同时设置容器背景为透明:

    .el-card {background-color: transparent !important;
    }
  2. 优先级:确保你的样式文件在 ElementPlus 样式之后加载,或使用 !important 提升优先级。

  3. 响应式设计:透明表格在深色或图案背景上效果更佳,需确保文字与背景有足够对比度。

完整示例

<template><div class="container"><el-card class="transparent-card"><el-table :data="tableData" stripe border><el-table-column prop="name" label="姓名"></el-table-column><el-table-column prop="age" label="年龄"></el-table-column><el-table-column prop="address" label="地址"></el-table-column></el-table></el-card></div>
</template><style scoped>
/* 透明表格样式 */
:deep(.el-table),
:deep(.el-table__header-wrapper),
:deep(.el-table__body-wrapper),
:deep(.el-table__row) {background-color: transparent !important;
}/* 可选:透明卡片 */
:deep(.el-card) {background-color: transparent !important;border: none !important;box-shadow: none !important;
}
</style>

    版权声明:

    本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

    我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com