Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill image to whole space in ion-img without losing aspect ratio?

My current progress stuck at something like this. I need help

enter image description here

I need the picture in the ion-img to fill its container without losing its aspect. here is my html code

<ion-col class='left-content'>
  <ion-img [src]='voucher.image'></ion-img>
</ion-col>

here is my scss code

ion-img {
  min-width: 5.7em;
  min-height: 5.7em;
  border-radius: 0.5em;
  @include my-img-shadow();
}

.left-content {
  padding-top: 0.8em;
  position: absolute;
  left: 0.5em;
}
like image 240
Thomas Kim Avatar asked Oct 06 '18 22:10

Thomas Kim


People also ask

How do you maintain the aspect ratio of an image?

By setting the width property to 100%, you are telling the image to take up all the horizontal space that is available. With the height property set to auto, your image's height changes proportionally with the width to ensure the aspect ratio is maintained. The end result is an image that scales up or down perfectly.

How do you fill a box with an image without distorting it?

In the Select Picture dialog box, locate the folder that contains the picture that you want to insert, select the picture file, and then click Insert. To maintain your picture's proportions (to prevent distortion) when it is inserted into the shape, check the Lock picture aspect ratio box, and then click OK.

How do I make an image occupy a whole div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

How do I completely fill an image in CSS?

The CSS object-fit property is used to specify how an <img> or <video> should be resized to fit its container. This property tells the content to fill the container in a variety of ways; such as "preserve that aspect ratio" or "stretch up and take up as much space as possible".


2 Answers

Use object-fit:cover.

ion-img {
    ...
    object-fit:cover;
  }
like image 129
Sudarshana Dayananda Avatar answered Sep 24 '22 00:09

Sudarshana Dayananda


.ion-img { 
  height: 100%; 
  width: 100%; 
  object-fit:cover; 
}
like image 32
Sameera Damith Avatar answered Sep 24 '22 00:09

Sameera Damith