Different CSS style on odd and even rows

霸气de小男生 提交于 2019-12-04 07:55:06

I'm not sure this will work cross-browser, i'd prefer jQuery myself, but css-only this should do the trick:

tr:nth-child(even) { ... }
tr:nth-child(odd) { ... }
Jeff Storey

You can use the nth-child selector http://reference.sitepoint.com/css/pseudoclass-nthchild, though it is not supported by all browsers.

You can also use jquery as described What is the best way to style alternating rows in a table?

You can do this with CSS3.

tr:nth-child(2n+1) /* targets all odd rows */
tr:nth-child(2n) /* targets all even rows */

you can simply use jquery and add class for odd rows like

$("tr:nth-child(odd)").addClass("odd");

and style it using css as

.odd{background-color:#657383}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!