In the following volist loop, how does one make the background color of each loop result different. acti {width: 100%; height: 70px; border: 1 pxdashed # 7E54DC; background-color: # E7E7E7; margin-bottom: 5px; font-size :...
In the following volist loop, how does one make the background color of each loop result different?
Such as the effect
. Acti {
Width: 100%;
Height: 70px;
// Border: 1px dashed # 7E54DC;
Background-color: # E7E7E7;
Margin-bottom: 5px;
Font-size: 12px;
}
">
<{$ Vo. ac_title}><{$ Vo. ac_charge}> yuan
<{$ Vo. ac_place}>
<{$ Vo. ac_time}>
Reply content:
In the following volist loop, how does one make the background color of each loop result different?
Such as the effect
. Acti {
Width: 100%;
Height: 70px;
// Border: 1px dashed # 7E54DC;
Background-color: # E7E7E7;
Margin-bottom: 5px;
Font-size: 12px;
}
">
<{$ Vo. ac_title}><{$ Vo. ac_charge}> yuan
<{$ Vo. ac_place}>
<{$ Vo. ac_time}>
1. add different classes, such as c1, c2... to define the styles of these classes through the index in the loop.
2. use the css selectorselector:nth-child(n)To add a style for a child element. N can be the nth specific number, starting from 1. It can also be an expression such:nth-child(2n)Even number,:nth-child(2n+1)An odd number.
Set the corresponding background colorclassAttribute. Then, retrieve the index values of different loops.classAttribute
.bg0{}.bg1{}.bg1{}
Take the index value in a loop
{foreach $key $val}...
{/foreach}
Try it. I hope it will help you.
function getRandomColor() { var strColor = '#'; for (var i = 0; i < 6; i++) { var currnet = Math.random() * 15 | 0; strColor += currnet.toString(16); } return strColor;}$(".acti").css('background-color',getRandomColor());
Heh, use js to implement a random.
Are you working on a webapp?