Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add border-radius to ion-img in Ionic 4

I need to add border-radius to ion-img but it seems shadow DOM won't let me modify.

HTML

<ion-img [src]="img-url" [alt]="alt"></ion-img>

CSS

ion-img  {
    border-radius: 10px !important;
}
like image 819
Jordan Lipana Avatar asked Oct 31 '19 09:10

Jordan Lipana


3 Answers

The correct, non-obvious, way to do this is with CSS shadow parts.

In this case ion-img has a shadow part image so our SCSS looks like:

ion-img::part(image) {
  border-radius: 10px;
}

Yes, the part has no quotes and is the full word "image" (not "img" we need the part name, not the target tag name).

like image 126
toxaq Avatar answered Nov 15 '22 11:11

toxaq


HTML

<ion-img [src]="img-url" class="your-img"></ion-img>

CSS

.your-img {
    border-radius: 10px !important;
    overflow: hidden;
}
like image 14
PabloM Avatar answered Nov 15 '22 12:11

PabloM


  1. put the image inside of card
    <ion-card>
        <ion-img  src="imag"></ion-img>                      
    </ion-card> 
  1. after that set the style of the image

  2. set image with and heigth to 100% in ion-img style

  3. modify the value of radius in the ion-card component

like image 1
hcallejas Avatar answered Nov 15 '22 12:11

hcallejas