仅一列中的备用行-CSS [英] Alternate rows in one column only - CSS

查看:95
本文介绍了仅一列中的备用行-CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为表格中的仅一列替换行着色?那是什么代码?

How do I color alternate rows in only one column in my table? What's the code for that?

推荐答案

如@ afranz409所述,理想的解决方案是创建一个类.但是,这可以通过特定于CSS的解决方案来完成,其浏览器功能有限(没有IE浏览器< 9):

As @afranz409 stated, the ideal solution would be to create a class. However, this can be done with a CSS specific solution, with limited browser capabilities (None of the IE browsers < 9):

table tr:nth-child(2n) > td:nth-child(1) {
    background-color: #eee;
}

换句话说,对于表格的第一行中的每一行,填充背景色#eee.如 JsFiddle 所示.

In other words, for every alternate row, within the first table column, fill the background color #eee. As seen on JsFiddle.

对于跨浏览器更兼容的解决方案,我建议在jQuery中使用此选择器:

For a more cross-browser compatible solution, I would recommend using this selector within jQuery:

$('table tr:nth-child(2n) > td:nth-child(1)').css("background-color", "#eee");

这篇关于仅一列中的备用行-CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆