定义table奇偶行样式

 今晚在网上找到一个感觉挺不错的table奇偶行样式,经过小整理一下放到这里收藏,同时与需要的朋友一起分享

.mytablecss
{
 font-size: 12px;
 color: #333333;
 text-decoration: none;
 width: 400px;
 cursor: hand;
 background-color: #FFFFFF;
 vertical-align: middle;
 text-align: center;
 cellspacing: 1;
}
.mytablecss tr
{
 background-color: expression(this.sectionRowIndex == 0 ? "#FFCCCC" : ((this.sectionRowIndex % 2 == 0) ? "#FFF0F0" : "#F0F0FF"));
 color: expression(this.sectionRowIndex == 0 ? "#FFFFFF" : "");
 font-weight: expression(this.sectionRowIndex == 0 ? "BOLD" : "");
 tableselect: expression(this.sectionRowIndex == 0 ? "" :
  (onmouseover = function(){
   this.style.backgroundColor = (this.style.backgroundColor != "#69cdff" ? "#69cdff" :
     (this.sectionRowIndex == 0 ? "#FFCCCC" : (this.sectionRowIndex % 2 == 0 ? "#FFF0F0" : "#F0F0FF" )
     )
    )
    },
        onmouseout = function(){
            this.style.backgroundColor = (this.style.backgroundColor != "#69cdff" ? "#69cdff" :
    (this.sectionRowIndex == 0 ? "#FFCCCC" : (this.sectionRowIndex % 2 == 0 ? "#FFF0F0" : "#F0F0FF"))
    )
   }
  )
    )
}
.mytablecss td
{
 background-color:expression(this.cellIndex == 0 ? (this.parentElement.sectionRowIndex == 0 ? "#FFCCCC" : "#DDDDDD") : null)
}

 

### 如何在 Vue 中自定义 `el-table` 样式 当使用Element UI中的`el-table`组件时,为了满足特定项目需求,可能需要调整默认样式。这可以通过多种方式来完成。 #### 方法一:全局覆盖样式 如果希望改变整个应用程序中所有表格的外观,则可以直接修改或扩展Element UI的主题变量文件。对于基于Sass构建的应用程序来说,这是非常方便的做法[^1]。 ```scss // 在 main.scss 或类似的全局样式文件里添加这些规则 @import "~element-ui/packages/theme-chalk/src/common/var"; $--color-primary: #ff0; // 修改主题色为例 ``` #### 方法二:局部作用域内的样式定制 针对单个页面上的某个具体表格实例进个性化设计更为常见。此时应该利用`:scoped` CSS特性,在模板内紧邻相应组件处编写CSS代码片段: ```html <template> <div class="customized-table"> <!-- 表格内容 --> </div> </template> <style scoped lang="less"> .customized-table { .el-table__header-wrapper th, .el-table__body tr:hover>td{ background-color:#f5f7fa !important; } } </style> ``` 上述例子展示了如何更改鼠标悬停时的颜色以及头部单元格背景色[^2]。 #### 方法三:通过API接口控制样式 除了直接操纵DOM元素外,还可以借助框架提供的API接口来进更加灵活的操作。例如,在Ant Design Vue中提供了`customRow`属性允许开发者动态设定每一的独特表现形式;而在Element Plus中也有相似的功能——即`row-style`和`cell-class-name`等选项可以帮助实现这一目标[^3]。 ```javascript const tableData = [ { date: '2016-05-02', name: '王小虎' }, ... ]; export default defineComponent({ setup() { const rowStyle = ({ row, rowIndex }) => ({ backgroundColor: rowIndex % 2 === 0 ? '#f9fafc' : '', }); return () => ( <ElTable data={tableData} style={{ width: '100%' }} row-style={rowStyle}> {/* 列定义 */} </ElTable> ); }, }); ``` 这段代码实现了奇偶不同底色的效果,增强了用户体验的同时也使得数据更容易区分[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值