Front-end big God and TP big God to see how to make the results in the loop every time the color is different

Source: Internet
Author: User

How does the loop in the following volist make each loop result in a different background color?
such as the effect
. acti{
width:100%;
height:70px;
border:1px dashed #7E54DC;
Background-color: #E7E7E7;
margin-bottom:5px;
font-size:12px;
}

                        " >                 <{$vo.ac_charge}>元                  <{$vo.ac_place}>                    <{$vo.ac_time}>                                             

Reply content:

How does the loop in the following volist make each loop result in a different background color?
such as the effect
. acti{
width:100%;
height:70px;
border:1px dashed #7E54DC;
Background-color: #E7E7E7;
margin-bottom:5px;
font-size:12px;
}

                        " >                 <{$vo.ac_charge}>元                  <{$vo.ac_place}>                    <{$vo.ac_time}>                                             

1. Add different classes through the index in the loop, such as C1, C2 ... Define the styles for these classes in styles.
2. Use the CSS selector to selector:nth-child(n) add a style to a child element. n can be a specific nth, starting from 1. It can also be an expression such as an :nth-child(2n) even-numbered, odd-numbered :nth-child(2n+1) item.

Set the properties of the corresponding background color class . And then eliminate the index value of the loop to take different class attributes

.bg0{}.bg1{}.bg1{}

The index value is taken at the time of the loop

{foreach $key $val}...{/foreach}

Try it, hope it helps 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());

Oh ah, with JS to achieve a full random.

Are you doing 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.