admin管理员组文章数量:1316009
I have a table that uses tablesorter and zebra striping for the table rows. I would like to add zebra striping to just one of the table COLUMNS to give it a little emphasis. like this:
I have a table that uses tablesorter and zebra striping for the table rows. I would like to add zebra striping to just one of the table COLUMNS to give it a little emphasis. like this:
Share Improve this question edited Oct 3, 2012 at 17:14 Diodeus - James MacFarlane 114k33 gold badges163 silver badges180 bronze badges asked Oct 3, 2012 at 17:11 TmacTmac 3111 silver badge16 bronze badges 1- 3 something is not right... i see text and pictures, but no code – yodog Commented Oct 3, 2012 at 17:15
3 Answers
Reset to default 8If you know the column index of the one you'd like to stripe, you can do it in CSS only, using :nth-of-type selectors like so:
tr:nth-of-type(even) td:nth-of-type(3) { background: rgba(0,0,0,0.1); }
(Where 3
is being used a placeholder for your target column index)
Another option would be to put a class on the header (or first td) of the column you want to stripe, and then use JS to stripe the other tds in the same column:
var col_to_stripe = $('th.stripe-this-one').index();
$('table.selectively-stripe').find('tr:odd')
.each(function() {
$(this).children('td')
.eq(col_to_stripe)
.css('background', 'pink');
});
The class is not necessary as obviously you can just put the column index you want as with the pure CSS approach, but it's better for clarity of code.
demo here: http://jsbin./axutal/2/edit
check this link
This can be done using jQuery without giving class names or id's.
$('tr:odd td:nth-child(4)').css('background','#999999'); /* For odd td's */
$('tr:even td:nth-child(4)').css('background','#DDDDDD'); /* For even td's */
For more information on this jQuery selector go through this link
You'll need an additional class name and corresponding CSS declaration for the TDs in that column.
本文标签: javascriptZebra striping to just one table columnStack Overflow
版权声明:本文标题:javascript - Zebra striping to just one table column - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741994772a2409822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论