当前位置:   article > 正文

Vue ElementUI table给表格一个斜线分隔线_vue表格实现表头的单元格斜杠分成两格

vue表格实现表头的单元格斜杠分成两格

方式一:参考element表格表头斜杠,让你的数据更有条理_el-table 表头斜线-CSDN博客

缺点:当屏幕放大或者缩小的时候,斜线会变形,得使用@media screen根据屏幕大小一个个去调整,调得太麻烦了,就放弃了这种方式,感兴趣的可以试试

  1. <el-table :data="tableData" border style="width: 100%">
  2. <el-table-column label="类型" width="150" align="center">
  3. <el-table-column label="月份" width="150"></el-table-column>
  4. </el-table-column>
  5. <el-table-column label="日期"></el-table-column>
  6. <el-table-column label="日期"></el-table-column>
  7. <el-table-column label="日期"></el-table-column>
  8. <el-table-column label="日期"></el-table-column>
  9. <el-table-column label="日期"></el-table-column>
  10. <el-table-column label="日期"></el-table-column>
  11. <el-table-column label="日期"></el-table-column>
  12. <el-table-column label="日期"></el-table-column>
  13. <el-table-column label="日期"></el-table-column>
  14. <el-table-column label="日期"></el-table-column>
  15. <el-table-column label="日期"></el-table-column>
  16. <el-table-column label="日期"></el-table-column>
  17. </el-table>
  18. 样式如下
  19. /deep/ .el-table thead.is-group tr:first-of-type th:first-of-type {
  20. border-bottom: none; // 去掉中间横线
  21. }
  22. /deep/ .el-table thead.is-group tr:first-of-type th:first-of-type div.cell {
  23. text-align: right; // 上边文字靠右
  24. }
  25. /deep/ .el-table thead.is-group tr:last-of-type th:first-of-type div.cell {
  26. text-align: left; // 下边文字靠左
  27. }
  28. /deep/ .el-table thead.is-group tr:first-of-type th:first-of-type:before {
  29. content: '';
  30. position: absolute;
  31. width: 1px;
  32. height: 100px; // 斜线长度
  33. top: 0;
  34. left: 0;
  35. background-color: #fff;
  36. opacity: 0.2;
  37. display: block;
  38. transform: rotate(-43deg);
  39. transform: rotate(-71deg);
  40. // transform: rotate(286deg);
  41. -webkit-transform-origin: top;
  42. transform-origin: top;
  43. }
  44. /deep/ .el-table thead.is-group tr:last-of-type th:first-of-type:before {
  45. content: '';
  46. position: absolute;
  47. width: 1px;
  48. height: 100px;
  49. bottom: 0;
  50. right: 0;
  51. background-color: #fff;
  52. opacity: 0.2;
  53. display: block;
  54. transform: rotate(-43deg);
  55. transform: rotate(-70deg);
  56. // transform: rotate(286deg);
  57. -webkit-transform-origin: bottom;
  58. transform-origin: bottom;
  59. }
  60. @media screen and(min-width: 550px) and (max-width: 1430px) {
  61. /deep/ .el-table thead.is-group tr:first-of-type th:first-of-type:before {
  62. transform: rotate(-62deg);
  63. }
  64. /deep/ .el-table thead.is-group tr:last-of-type th:first-of-type:before {
  65. transform: rotate(-62deg);
  66. }
  67. }
  68. @media screen and(min-width: 1430px) and (max-width: 1450px) {
  69. /deep/ .el-table thead.is-group tr:first-of-type th:first-of-type:before {
  70. transform: rotate(-62deg);
  71. }
  72. /deep/ .el-table thead.is-group tr:last-of-type th:first-of-type:before {
  73. transform: rotate(-62deg);
  74. }
  75. }

方式二:参考滑动验证页面

页面放大缩小斜线位置都不受影响

  1. <el-table :data="tableData" border style="width: 100%">
  2. <el-table-column :resizable="false" class-name="column-custom" prop="date" label="日期" width="120">
  3. <template slot="header" slot-scope="scope">
  4. <div class="header-div">
  5. <div class="header-col1">区域</div>
  6. <div class="header-col2">类型</div>
  7. <div class="header-line"></div>
  8. </div>
  9. </template>
  10. </el-table-column>
  11. <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
  12. <el-table-column prop="address" label="地址"> </el-table-column>
  13. <el-table-column label="1月"></el-table-column>
  14. <el-table-column label="2月"></el-table-column>
  15. <el-table-column label="3月"></el-table-column>
  16. <el-table-column label="4月"></el-table-column>
  17. <el-table-column label="5月"></el-table-column>
  18. <el-table-column label="6月"></el-table-column>
  19. <el-table-column label="7月"></el-table-column>
  20. <el-table-column label="8月"></el-table-column>
  21. <el-table-column label="9月"></el-table-column>
  22. <el-table-column label="10月"></el-table-column>
  23. <el-table-column label="11月"></el-table-column>
  24. <el-table-column label="12月"></el-table-column>
  25. </el-table>
  26. 样式:
  27. /deep/.column-custom {
  28. padding: 0px !important;
  29. }
  30. /deep/.el-table--border .el-table__cell:first-child .cell {
  31. padding: 0 !important;
  32. }
  33. .header-div {
  34. height: 50px;
  35. position: relative;
  36. }
  37. .header-col1 {
  38. position: absolute;
  39. left: 0;
  40. bottom: 0;
  41. }
  42. .header-col2 {
  43. position: absolute;
  44. right: 0;
  45. top: 0;
  46. }
  47. .header-line {
  48. padding-left: 0;
  49. width: 1px;
  50. height: 150px;
  51. transform: rotate(-67deg); /*这里需要自己调整,根据线的位置*/
  52. -webkit-transform-origin: top;
  53. transform-origin: top;
  54. background-color: #fff;
  55. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/113658
推荐阅读
相关标签
  

闽ICP备14008679号