Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing ion-input border color on focus

I used some CSS to style the ion-input field, but I want the border of the field to change on focus

CSS

.input-field {
    background: rgba(250,250,250,1);
    border: solid 1px rgba(218,218,218,1);
    margin-bottom: 16px;
    height: 50px;
    border-radius: 20px;
    padding-left: 16px;
}

HTML

<div class="input">
    <ion-label class="prompt-text" position="stacked">Email</ion-label>
    <br><br>
    <ion-input class="input-field" placeholder="[email protected]"></ion-input>  
</div>

This is how the field looks

enter image description here

I tried to use the below CSS, but it didn't work

.input-field:focus {
    border: solid 2px black;
}

UPDATE

I am able to change the ion-input field border color using Typescript by handling the events (ionFocus) and (ionBlur)

  <div class="input">
    <ion-label position="stacked">Email</ion-label>
    <br><br>
    <ion-input autocomplete="off" [(ngModel)]="email" id="email-input" (ionFocus)="focusEmail()" (ionBlur)="unFocusEmail()" class="input-field" placeholder="[email protected]"></ion-input>  
  </div>

Typescript

focusEmail(){
    document.getElementById('email-input').style.border = "solid 2px #107CF1";
  }

 unFocusEmail(){
    document.getElementById('email-input').style.border = "solid 1px rgba(218,218,218,1)";
  }
like image 257
Mohsen Avatar asked Oct 16 '25 05:10

Mohsen


2 Answers

Simple way is CSS:

.has-focus {
  border: 2px solid #5b9bd1 !important;
}
like image 196
The Best Avatar answered Oct 17 '25 20:10

The Best


ion-item.item-has-focus {
    --highlight-background:black;
}
like image 20
dilip Avatar answered Oct 17 '25 19:10

dilip



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!