Change ion-input underline color in Ionic 4

拟墨画扇 提交于 2019-12-10 19:23:22

问题


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


回答1:


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

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



回答2:


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;
  }
}



回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/53214736/change-ion-input-underline-color-in-ionic-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!