0

I am trying to change the background of the ion-radio-group below to match the other rows:

enter image description here

I have shown my HTML & CSS below.

I tried adding the rowStyle class to the row. That changes the background of the row, but the radio button's are still appearing blue.

If I update the --ion-background-color value in my CSS for ion-content, the radio button background does change, but so does the entire page.

I just want all the rows to match.

Can someone please tell me how to do this?

<ion-content>
  <ion-grid style="width: 75%">

    <ion-radio-group [(ngModel)]="userType">
      <ion-row class="rowStyle">
        <ion-item>
          <ion-label>Customer</ion-label>
          <ion-radio value="customer"></ion-radio>
        </ion-item>
        <ion-item>
          <ion-label>Supplier</ion-label>
          <ion-radio value="supplier"></ion-radio>
        </ion-item>
      </ion-row>
    </ion-radio-group>

    <ion-row class="rowStyle">
      <ion-icon name="person" color="secondary"></ion-icon>
      <ion-input type="text" placeholder="Your Name" [(ngModel)]="name"></ion-input>
    </ion-row>

    <ion-row class="rowStyle">
      <ion-icon name="mail" color="secondary"></ion-icon>
      <ion-input type="email" placeholder="Your Email" [(ngModel)]="email"></ion-input>
    </ion-row>

    <ion-row class="rowStyle">
      <ion-icon name="key" color="secondary"></ion-icon>
      <ion-input type="password" placeholder="Your Password" [(ngModel)]="password"></ion-input>
    </ion-row>

    <ion-button expand="block" shape="round" fill="outline" color="light" style="margin-top: 20px;" (click)="signUp()">Sign Up</ion-button>
  </ion-grid>
</ion-content>



ion-content {
    --ion-background-color:#3dc2ff;
  }

  .logo { 
    font-size: 25vh;
    margin-top: 40px;
    margin-bottom: 20px;
  }

  h1, h6 {
    color: white;
    font-size: 1em;
    background-color: danger
  }

  .rowStyle {
    background-color: white;
    padding-left: 10px;
    border-radius: 30px;
    margin-bottom: 10px;

    ion-icon {
      margin-top: 13px;
      margin-right: 10px;
    }
  }

I added the rowStyleclass to the row. The background of the tag is appearing white, but the background of the 2 radio buttons isn't changing.

Here is what it looks like when I tried to apply the 1st answer:

enter image description here

user9847788
  • 2,135
  • 5
  • 31
  • 79

1 Answers1

0

You can handle it in 2 ways as mentioned below:

  1. Create a selector class and add the color. OR
  2. You should use the ion-item to get value to be changed:

ion-content {
  --ion-background-color: #3dc2ff;
}

.logo {
  font-size: 25vh;
  margin-top: 40px;
  margin-bottom: 20px;
}

h1,
h6 {
  color: white;
  font-size: 1em;
  background-color: danger
}

.rowStyle {
  background-color: white;
  padding-left: 10px;
  border-radius: 30px;
  margin-bottom: 10px;
}

ion-item {
  padding: 5px;
  border: 1px solid black;
  background-color: red;
  color: white;
}
<ion-content>
  <ion-grid style="width: 75%">

    <ion-radio-group [(ngModel)]="userType">
      <ion-row class="rowStyle">
        <ion-item>
          <ion-label>Customer</ion-label>
          <ion-radio value="customer"></ion-radio>
        </ion-item>
        <ion-item>
          <ion-label>Supplier</ion-label>
          <ion-radio value="supplier"></ion-radio>
        </ion-item>
      </ion-row>
    </ion-radio-group>

    <ion-row class="rowStyle">
      <ion-icon name="person" color="secondary"></ion-icon>
      <ion-input type="text" placeholder="Your Name" [(ngModel)]="name"></ion-input>
    </ion-row>

    <ion-row class="rowStyle">
      <ion-icon name="mail" color="secondary"></ion-icon>
      <ion-input type="email" placeholder="Your Email" [(ngModel)]="email"></ion-input>
    </ion-row>

    <ion-row class="rowStyle">
      <ion-icon name="key" color="secondary"></ion-icon>
      <ion-input type="password" placeholder="Your Password" [(ngModel)]="password"></ion-input>
    </ion-row>

    <ion-button expand="block" shape="round" fill="outline" color="light" style="margin-top: 20px;" (click)="signUp()">Sign Up</ion-button>
  </ion-grid>
</ion-content>

OR

using selector class:

ion-content {
  --ion-background-color: #3dc2ff;
}

.logo {
  font-size: 25vh;
  margin-top: 40px;
  margin-bottom: 20px;
}

h1,
h6 {
  color: white;
  font-size: 1em;
  background-color: danger
}

.rowStyle {
  background-color: white;
  padding-left: 10px;
  border-radius: 30px;
  margin-bottom: 10px;
}

.radioBtn {
  padding: 5px;
  border: 1px solid black;
  background-color: red;
}
<ion-content>
  <ion-grid style="width: 75%">

    <ion-radio-group [(ngModel)]="userType">
      <ion-row class="rowStyle">
        <ion-item>
          <ion-label class="radioBtn">Customer</ion-label>
          <ion-radio value="customer"></ion-radio>
        </ion-item>
        <ion-item>
          <ion-label class="radioBtn">Supplier</ion-label>
          <ion-radio value="supplier"></ion-radio>
        </ion-item>
      </ion-row>
    </ion-radio-group>

    <ion-row class="rowStyle">
      <ion-icon name="person" color="secondary"></ion-icon>
      <ion-input type="text" placeholder="Your Name" [(ngModel)]="name"></ion-input>
    </ion-row>

    <ion-row class="rowStyle">
      <ion-icon name="mail" color="secondary"></ion-icon>
      <ion-input type="email" placeholder="Your Email" [(ngModel)]="email"></ion-input>
    </ion-row>

    <ion-row class="rowStyle">
      <ion-icon name="key" color="secondary"></ion-icon>
      <ion-input type="password" placeholder="Your Password" [(ngModel)]="password"></ion-input>
    </ion-row>

    <ion-button expand="block" shape="round" fill="outline" color="light" style="margin-top: 20px;" (click)="signUp()">Sign Up</ion-button>
  </ion-grid>
</ion-content>
Manjuboyz
  • 6,978
  • 3
  • 21
  • 43
  • Thanks for your response. But I tried your first solution, & that isn't working. I've attached an image above to show how it is displaying with my code – user9847788 Apr 01 '20 at 17:13