Change ion-input underline color in Ionic 4

Viewed 25314

How can we change the default underline color of a ion-text in only a single page in Ionic 4?

5 Answers

The underline is actually a part of the ion-item, not the ion-input.

ion-item {
  --border-color: var(--ion-color-danger, #f1453d);
}

Ionic 4.x uses CSS Custom Properties for most of the time.

src/app/pages/test/test.page.scss

:host {
    ion-item {
        --border-color: white; // default underline color
        --highlight-color-invalid: red; // invalid underline color
        --highlight-color-valid: green; // valid underline color
    }
}

If necessary, please check the other custom properties here.

For Ionic V4.X is a little bit diffrent.

You can open specific_page.scss file where you want to change ion-input border when input value is Valid o Invalid

Change the colors of the following class, like this:

:host {
   .item-interactive.ion-invalid{
    --highlight-background: yellow !important;
  }
  .item-interactive.ion-valid{
    --highlight-background: black !important;
  }
}

Try this css

.item-has-focus{
   --highlight-background: #e2e2e2;
}

To aggregate in app.scss file

.ios {
    .item-has-focus.ion-invalid {
      --border-color: var(--ion-color-danger, #f1453d);
    }

   .ion-valid {
      --border-color: var(
        --ion-item-border-color,
        var(--ion-border-color, var(--ion-color-step-150, rgba(255, 255, 255, 0.8)))
      );
   }

   .custom-item {
      --background: transparent;
      color: #fff !important;
      --background-focused: transparent;
   }
}

.md.custom-item {
    --background: transparent;
    color: #fff !important;
    --background-focused: transparent;
    --border-color: var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-150, rgba(255, 255, 255, 0.8)))
    );
}

Or use class to you custom .custom-item.hydrated.ion-touched.ion-dirty.ion-invalid.item-label.item-interactive.item-input.item-has-focus.item.ios.ion-focusable

Related