Jump to content

css nth-child


NaniG

Recommended Posts

Hi to all,

 

As per my client suggested, i need to change the info box background color for every info box (circular way). So i used the CSS3 pseudo nth-child algoritham to assign each info box background color with different background colors.

 

Here is my html code

<div class="row flexslider carousel" id="appList">
    <ul class="slides">
        <li>
            <div class="col-lg-3 col-md-6 col-sm-6">
                <div class="info-box">
                    <img src="img/shortcuts/money.png" alt="">
                    <div class="count">1</div>
                    <div class="title">New users</div>
                    <div class="desc">Purchase</div>
                    <div class="desc f-bold">Test</div>
                </div>
            </div>
        </li>
        <li>
            <div class="col-lg-3 col-md-6 col-sm-6">
                <div class="info-box">
                    <img src="img/shortcuts/money.png" alt="">
                    <div class="count">2</div>
                    <div class="title">New users</div>
                    <div class="desc">Purchase</div>
                    <div class="desc f-bold">Test</div>
                </div>
            </div>
        </li>
        <li>
            <div class="col-lg-3 col-md-6 col-sm-6">
                <div class="info-box">
                    <img src="img/shortcuts/money.png" alt="">
                    <div class="count">3</div>
                    <div class="title">New users</div>
                    <div class="desc">Purchase</div>
                    <div class="desc f-bold">Test</div>
                </div>
            </div>
        </li>
        <li>
            <div class="col-lg-3 col-md-6 col-sm-6">
                <div class="info-box">
                    <img src="img/shortcuts/money.png" alt="">
                    <div class="count">4</div>
                    <div class="title">New users</div>
                    <div class="desc">Purchase</div>
                    <div class="desc f-bold">Test</div>
                </div>
            </div>
        </li>
        <li>
            <div class="col-lg-3 col-md-6 col-sm-6">
                <div class="info-box">
                    <img src="img/shortcuts/money.png" alt="">
                    <div class="count">5</div>
                    <div class="title">New users</div>
                    <div class="desc">Purchase</div>
                    <div class="desc f-bold">Test</div>
                </div>
            </div>
        </li>
    </ul>
</div>

Here is CSS code

.info-box {
    min-height: 140px;
    border: 1px solid black;
    margin-bottom: 30px;
    padding: 20px;
    color: white;
    -webkit-box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.35), 0 3px 1px -1px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.35), 0 3px 1px -1px rgba(0, 0, 0, 0.1);
    box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.35), 0 3px 1px -1px rgba(0, 0, 0, 0.1);
    }

.info-box i {
    display: block;
    height: 100px;
    font-size: 60px;
    line-height: 100px;
    width: 100px;
    float: left;
    text-align: center;
    border-right: 2px solid rgba(255, 255, 255, 0.5);
    margin-right: 20px;
    padding-right: 20px;
    color: rgba(255, 255, 255, 0.75);
    }

.info-box img {
    display: block;
    height: auto;
    font-size: 46px;
    line-height: 46px;
    width: auto;
    float: left;
    text-align: center;
    border-right: 2px solid rgba(255, 255, 255, 0.5);
    margin-right: 20px;
    padding-right: 20px;
    color: rgba(255, 255, 255, 0.75);
    }
.info-box .count {
    margin-top: -10px;
    font-size: 34px;
    font-weight: 700;
    }
.info-box .title {
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 600;
    }
.info-box .desc {
    margin-top: 10px;
    font-size: 12px;
    }
#appList ul.slides li div div.info-box:nth-child(5n+1) {
    background: #fabb3d;
    border: 1px solid #f9aa0b;
    }
#appList ul.slides li div div.info-box:nth-child(5n+2) {
    background: #ff5454;
    border: 1px solid #ff2121;
    }
#appList ul.slides li div div.info-box:nth-child(5n+3) {
    background: #67c2ef;
    border: 1px solid #39afea;
    }
#appList ul.slides li div div.info-box:nth-child(5n+4) {
    background: #79c447;
    border: 1px solid #61a434;
    }
#appList ul.slides li div div.info-box:nth-child(5n) {
    background: #20a8d8;
    border: 1px solid #1985ac;
    }

But when i tried with the above code, the info box only accepts (5n+1) CSS code.

 

Can any one please suggest me the way to get the solution.

 

Link to comment
https://forums.phpfreaks.com/topic/291951-css-nth-child/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.