vue+scss+element-ui實(shí)現(xiàn)表格表頭斜杠一分為三方式
vue+scss+element-ui表格表頭斜杠一分為三
看了網(wǎng)上很多博客,大部分都是表頭第一個(gè)斜線一份為2的樣式,今天寫一個(gè)樣式一分為3的樣式,可以根據(jù)項(xiàng)目情況適當(dāng)增加或減少分割
<template> <div> <el-table :data="tableData" border style="width: 100%"> <el-table-column :resizable="false" class-name="column-custom" prop="date" label="日期" width="120" > <template slot="header" slot-scope="scope"> <div class="header-div"> <div class="header-col1">區(qū)域</div> <div class="header-col2">類型</div> <div class="header-col3">水量</div> <div class="header-line1"></div> <div class="header-line2"></div> </div> </template> </el-table-column> <el-table-column prop="name" label="姓名" width="180"> </el-table-column> <el-table-column prop="address" label="地址"> </el-table-column> <el-table-column label="1月" prop="January" ></el-table-column> <el-table-column label="2月" prop="February" ></el-table-column> <el-table-column label="3月" prop="March" ></el-table-column> </el-table> </div> </template>
<script> export default { data() { return { tableData: [ {date:"2024",address:"陜西省西安市吉祥村",January:'January',February:"February",March:'March'} ], }; }, }; </script>
<style lang="scss" scoped> /deep/.column-custom { padding: 0px; } .header-div { height: 80px; position: relative; } .header-col1 { position: absolute; left: 0; bottom: 0; } .header-col2 { position: absolute; right: 0; top: 0; } .header-col3 { position: absolute; right: 0; bottom: 0; } /deep/.el-table--border .el-table__cell:first-child .cell { padding: 0; } .header-line1 { padding-left: 0; width: 1px; height: 150px; transform: rotate(-67deg); /*這里需要自己調(diào)整,根據(jù)線的位置*/ -webkit-transform-origin: top; transform-origin: top; background-color: red;/*這里需要自己調(diào)整,根據(jù)線條的顏色*/ } .header-line2 { padding-left: 0; width: 1px; height: 150px; transform: rotate(-41deg); /*這里需要自己調(diào)整,根據(jù)線的位置*/ -webkit-transform-origin: top; transform-origin: top; background-color: blue;/*這里需要自己調(diào)整,根據(jù)線條的顏色*/ position: absolute; top: 0; left: 0; } </style>
element ui el-table實(shí)現(xiàn)帶斜線的雙表頭
實(shí)現(xiàn)思路
通過(guò)嵌套表頭將兩個(gè)標(biāo)題設(shè)置在一個(gè)單元格內(nèi),再通過(guò) CSS 樣式增加斜線效果。
知識(shí)點(diǎn):el-table、::before、transform
實(shí)現(xiàn)的代碼
<el-table :data="tableData" border> <!--重點(diǎn)代碼:采用嵌套的方式--> <el-table-column label="數(shù)據(jù)" align="right" width="150"> <el-table-column prop="name" label="數(shù)據(jù)指標(biāo)" width="150"> </el-table-column> </el-table-column> <el-table-column v-for="(col, i) in columnList" :key="i" :prop="col.prop" :label="col.label" align="center" > <template v-if="col.children"> <el-table-column v-for="(item, index) in col.children" :key="index" :prop="item.prop" :label="item.label" > </el-table-column> </template> </el-table-column> </el-table>
<style scoped> /*表頭斜線*/ /*::v-deep 這里主要的作用就是用來(lái)強(qiáng)制修改element默認(rèn)的樣式*/ ::v-deep .el-table thead.is-group th { background: none; padding: 0px; } ::v-deep .el-table thead.is-group tr:first-of-type th:first-of-type { border-bottom: none;/*中間的橫線去掉*/ } ::v-deep .el-table thead.is-group tr:first-of-type th:first-of-type div.cell { text-align: right;/*上邊文字靠右*/ } ::v-deep .el-table thead.is-group tr:last-of-type th:first-of-type div.cell { text-align: left;/*下邊文字靠左*/ } /*核心代碼*/ ::v-deep .el-table thead.is-group tr:first-of-type th:first-of-type:before { content: ""; position: absolute; width: 1px; height: 80px;/*斜線的長(zhǎng)度*/ top: 0; left: 0; background-color: #18449C; opacity: 1; display: block; transform: rotate(-61deg);/*調(diào)整斜線的角度*/ -webkit-transform-origin: top; transform-origin: top; } ::v-deep .el-table thead.is-group tr:last-of-type th:first-of-type:before { content: ""; position: absolute; width: 1px; height: 80px;/*斜線的長(zhǎng)度*/ bottom: 0; right: 0; background-color: #18449C; opacity: 1; display: block; transform: rotate(-62deg);/*調(diào)整斜線的角度*/ -webkit-transform-origin: bottom; transform-origin: bottom; } </style>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue項(xiàng)目使用PostCSS做h5頁(yè)面的屏幕適配的配置步驟
PostCSS 是一個(gè)用 JavaScript 編寫的工具,用于將 CSS 轉(zhuǎn)換為另一種 CSS,在做h5頁(yè)面的屏幕適配時(shí),結(jié)合 PostCSS 的一些插件能輕松實(shí)現(xiàn),下面以結(jié)合 postcss-pxtorem 插件為例,詳細(xì)介紹配置步驟,需要的朋友可以參考下2025-02-02解決vue語(yǔ)法會(huì)有延遲加載顯現(xiàn){{xxx}}的問(wèn)題
今天小編就為大家分享一篇解決vue語(yǔ)法會(huì)有延遲加載顯現(xiàn){{xxx}}的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11詳解vue與后端數(shù)據(jù)交互(ajax):vue-resource
本篇文章主要介紹了詳解vue與后端數(shù)據(jù)交互(ajax):vue-resource,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03Vue前端如何設(shè)置Cookie和鑒權(quán)問(wèn)題詳解
這篇文章主要介紹了前端如何設(shè)置和使用Cookie,并對(duì)比了Cookie和Token在鑒權(quán)中的優(yōu)缺點(diǎn),文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-02-02Vue解決echart在element的tab切換時(shí)顯示不正確問(wèn)題
這篇文章主要介紹了Vue解決echart在element的tab切換時(shí)顯示不正確問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08基于vue 添加axios組件,解決post傳參數(shù)為null的問(wèn)題
下面小編就為大家分享一篇基于vue 添加axios組件,解決post傳參數(shù)為null的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03