【发布时间】:2016-07-28 09:47:54
【问题描述】:
我想使用这个插件来显示博客文章,但不是将图像作为背景,客户想要不同颜色的图像。从这里的另一篇文章中,我已经找到了我认为可以执行此操作的代码,但我无法将它带到网站上!这是我编写的似乎在这里工作的代码。 Example where code is working.
这是目前有问题的网站。 The div site where it isn't working like it should...
你会看到所有的颜色都是一样的,而不是像他们应该的那样交替... 任何有用的建议将不胜感激为什么这不起作用。
这是上面 jsfiddle 中的 CSS 和 JS。
CSS:
.custom_tdgclients_grid{width:20%;height:90px;display:inline-block}
.custom_tdgclients_grid{background:#a7948b}
.custom_tdgclients_grid:nth-child(2n){background-color:rgb(232, 73, 73)!important;}
.custom_tdgclients_grid:nth-child(3n){background-color:rgb(83, 71, 65)!important;}
.custom_tdgclients_grid:nth-child(4n){background-color:#e8d2af!important;}
.custom_tdgclients_grid:nth-child(5n){background-color:rgb(131, 119, 113)!important;}
.custom_tdgclients_grid:nth-child(6n){background-color:rgb(216, 184, 133)!important;}
.custom_tdgclients_grid:nth-child(7n){background-color:rgb(201, 93, 93)!important;}
.custom_tdgclients_grid:nth-child(8n){background-color:#e8d2af!important;}
还有 Javascript:
$('.custom_tdgclients_grid:nth-child(2n)').css({'background-color':'rgb(232, 73, 73)'});
$('.custom_tdgclients_grid:nth-child(3n)').css({'background-color':'rgb(83, 71, 65)'});
$('.custom_tdgclients_grid:nth-child(4n)').css({'background-color':'#e8d2af'});
$('.custom_tdgclients_grid:nth-child(5n)').css({'background-color':'rgb(131, 119, 113)'});
$('.custom_tdgclients_grid:nth-child(6n)').css({'background-color':'rgb(216, 184, 133)'});
$('.custom_tdgclients_grid:nth-child(7n)').css({'background-color':'rgb(201, 93, 93)'});
$('.custom_tdgclients_grid:nth-child(8n)').css({'background-color':'rgb(181, 128, 101)'});
【问题讨论】:
标签: javascript css wordpress background alternating