Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling two rows in ng-repeat with same colour for n items

I have an array of objects which I need to show as list, required design is

enter image description here

I tried the code below

.odd{
    background-color: grey;
}

.even{
    background-color: #d09683;
}
<ion-audio-track track="track" ng-repeat="x in array" ng-if="track.Size!=0">
        <div class="card" ng-class="{'even':$index%2, 'odd':!($index%2)}">
            <div class="row">
              //item prints here
            </div>
          </div>
  </ion-audio-track>

but what I got is

enter image description here

like image 292
Sabreena Avatar asked Dec 13 '25 00:12

Sabreena


2 Answers

Here is one more solution:

div.card {
    background-color: grey;
}

div.card:nth-child(4n), div.card:nth-child(4n-1) {
    background-color: #d09683;
}
like image 60
Banzay Avatar answered Dec 14 '25 15:12

Banzay


First of all we will apply one background-color for all list items.

ul li {
  background: blue;
}

In second step we will use 2 css selectors that will override background of specific list items by creating an even pattern:

ul li:nth-child(4n + 1),
ul li:nth-child(4n + 2) {
  background: green;
}

Image Output:

Output Image

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

ul li {
  background: blue;
  margin-bottom: 10px;
  padding: 5px 10px;
  color: white;
}

ul li:nth-child(4n + 1),
ul li:nth-child(4n + 2) {
  background: green;
}
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
  <li>13</li>
  <li>14</li>
  <li>15</li>
  <li>16</li>
  <li>17</li>
  <li>18</li>
  <li>19</li>
  <li>20</li>
</ul>
like image 33
Mohammad Usman Avatar answered Dec 14 '25 15:12

Mohammad Usman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!