Different background-color for odd / even with ion-cards

hi there,

i am using some ion-cards within a ion-row like so:

    <ion-row responsive-sm>
	<ion-col col-12 col-md-6 align-self-stretch align-self-center *ngFor="let question of question_set; let i=index">
      <ion-card class="card-custom-bg">
        ...
	  <ion-card>
	<ion-col>
</ion-row>

now i’d like to color every even card with a red background using

.card-custom-bg:nth-of-type(even) {
    background:red; 
}

but that does not work.

any ideas?
thanks a lot!

1 Like

You are repeating ion-col and not ion-card. That means ion-card is always going to be odd.

Something like this should work:

ion-col:nth-of-type(even) {
  ion-card {
    background: red;
  }
}
1 Like

Ah, of course. Thanks a lot.

How can I Change the background color of an ion-card…?