0


【ElementUI样式优化1】el-table 修改斑马格样式、修改滚动条样式、添加表头边框、删除表格边框划线

重要的不是过去,而是你怎末看待过去,而我们对过去的看法,是可以改变的。


效果预览:

(1)删除表格外框,内框。

(2)添加表头边框,修改表头文字大小、颜色

(3)斑马格修改颜色,选中行高亮颜色修改

(4)修改滚动条样式



一、原始样式说明

Element - The world's most popular Vue UI framework

1.斑马纹表格

使用strip属性,即可形成如图效果。

2.带状态表格

可以通过指定 Table 组件的

  1. row-class-name

属性来为 Table 中的某一行添加 class,表明该行处于某种状态。

二、修改el-table样式

1.设置表格行高

  1. // 设置表格行高度
  2. ::v-deep .el-table__body tr,
  3. ::v-deep .el-table__body td {
  4. padding: 0;
  5. height: 54px;
  6. }

2.修改背景色、字体颜色

  1. // 表格内背景颜色
  2. ::v-deep .el-table th,
  3. ::v-deep .el-table tr,
  4. ::v-deep .el-table td {
  5. background-color:#063570; // 背景透明
  6. border: 0px;
  7. color: #93dcfe; // 修改字体颜色
  8. font-size: 24px;
  9. height: 5px;
  10. font-family: Source Han Sans CN Normal, Source Han Sans CN Normal-Normal;
  11. font-weight: Normal;
  12. }
  1. // 去掉最下面的那一条线
  2. .el-table::before {
  3. height: 0px;
  4. }

3.设置表头字体

在表格组件部分添加 :header-cell-style。注意里面不支持font-weight写法,需要使用驼峰写法。

  1. <el-table
  2. :data="tableData"
  3. :header-cell-style="{
  4. color: '#fff',
  5. background: '#0a3370',
  6. fontWeight: '700',
  7. }"
  8. max-height="720"
  9. >
  10. </el-table>
  1. // 修改表头样式-加边框
  2. ::v-deep .el-table__header-wrapper {
  3. border: solid 1px #04c2ed;
  4. // box-sizing: border-box;
  5. }

4.修改斑马格样式

(1)使用表格属性 :row-class-name="tableRowClassName"

(2)添加JS 方法

  1. tableRowClassName({ row, rowIndex }) {
  2. if (rowIndex % 2 == 0) {
  3. return "";
  4. } else {
  5. return "warning-row";
  6. }
  7. },

(3)添加CSS的warning-row样式

  1. // 表格斑马自定义颜色
  2. ::v-deep .el-table__row.warning-row {
  3. background: #063570;
  4. }

5.修改hove行高亮颜色

  1. // 修改高亮当前行颜色
  2. ::v-deep .el-table tbody tr:hover > td {
  3. background: #063570 !important;
  4. }
  5. // 取消当前行高亮--此时不能进行行点击操作
  6. // ::v-deep .el-table tbody tr {
  7. // pointer-events: none;
  8. // }

6.修改滚动条样式

  1. // 滚动条样式
  2. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  3. background-color: #063570;
  4. }
  5. ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  6. width: 10px;
  7. opacity: 0.5;
  8. }
  9. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  10. border-radius: 15px;
  11. background-color: #0257aa;
  12. }

三、代码整合速览

  1. <el-table
  2. :data="tableData"
  3. key='xqtable'
  4. @row-click="handleClickChange"
  5. style="width: 90%; margin: auto"
  6. :highlight-current-row="false"
  7. :header-cell-style="{
  8. color: '#fff',
  9. background: '#0a3370',
  10. fontWeight: '700',
  11. }"
  12. :row-class-name="tableRowClassName"
  13. max-height="720"
  14. >
  15. <el-table-column label="序号" prop="index" width="120" align="center">
  16. <template slot-scope="scope">
  17. <span>{{ scope.$index + 1 }}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column prop="paramterName" label="参数名" width="500">
  21. <template slot-scope="scope">
  22. <span @click="showDetailChart(scope.row)">{{
  23. scope.row.paramterName
  24. }}</span>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  1. methods:{
  2. // 表格斑马格:row-class-name="tableRowClassName"
  3. tableRowClassName({ row, rowIndex }) {
  4. if (rowIndex % 2 == 0) {
  5. return "";
  6. } else {
  7. return "warning-row";
  8. }
  9. },
  10. // 行点击事件
  11. handleClickChange(row, event, column) {
  12. console.log('点击行',row.index, this.myChart, row, column, row.active);
  13. },
  14. }
  1. // 表格部分样式
  2. // 最外层透明
  3. ::v-deep .el-table,
  4. ::v-deep .el-table__expanded-cell {
  5. background-color: transparent;
  6. color: #93dcfe;
  7. font-size: 24px;
  8. }
  9. // 表格内背景颜色
  10. ::v-deep .el-table th,
  11. ::v-deep .el-table tr,
  12. ::v-deep .el-table td {
  13. background-color: transparent;
  14. border: 0px;
  15. color: #93dcfe;
  16. font-size: 24px;
  17. height: 5px;
  18. font-family: Source Han Sans CN Normal, Source Han Sans CN Normal-Normal;
  19. font-weight: Normal;
  20. }
  21. // 去掉最下面的那一条线
  22. .el-table::before {
  23. height: 0px;
  24. }
  25. // 设置表格行高度
  26. ::v-deep .el-table__body tr,
  27. ::v-deep .el-table__body td {
  28. padding: 0;
  29. height: 54px;
  30. }
  31. // 修改高亮当前行颜色
  32. ::v-deep .el-table tbody tr:hover > td {
  33. background: #063570 !important;
  34. }
  35. // 取消当前行高亮
  36. // ::v-deep .el-table tbody tr {
  37. // pointer-events: none;
  38. // }
  39. // 修改表头样式-加边框
  40. ::v-deep .el-table__header-wrapper {
  41. border: solid 1px #04c2ed;
  42. // box-sizing: border-box;
  43. }
  44. // 表格斑马自定义颜色
  45. ::v-deep .el-table__row.warning-row {
  46. background: #063570;
  47. }
  48. // 滚动条样式
  49. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  50. background-color: #063570;
  51. }
  52. ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  53. width: 10px;
  54. opacity: 0.5;
  55. }
  56. ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  57. border-radius: 15px;
  58. background-color: #0257aa;
  59. }

附:

背景图片

标签: 前端 javascript css

本文转载自: https://blog.csdn.net/Sabrina_cc/article/details/124408272
版权归原作者 小白Rachel 所有, 如有侵权,请联系我们删除。

“【ElementUI样式优化1】el-table 修改斑马格样式、修改滚动条样式、添加表头边框、删除表格边框划线”的评论:

还没有评论