Front-end God and tp God to see how to make the results in the loop different colors each time-php Tutorial

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.