0

I am trying to add a heart ion icon to every image in my photo gallery app. This will eventually allow the user to like the image. As you can see from the 1st image below, the heart icon is added to every image apart from two and I can't figure out why?

enter image description here

Also in the 2nd image below you can see that the heart is added to the page where there aren't any images. I also can understand why this is happening?

enter image description here

Here is where the icon is added to the html code:

<a style="cursor: pointer">
    <div class="list-group-item">
        <div class="like-icon-container">
            <ion-icon class="like-icon" name="heart"></ion-icon>
        </div>
        <img [src]="image.imagePath" alt="Praying to the Sun" [ngStyle]="{'height': image.heightSize, 'width': image.widthSize}" class="image-item">
    </div>
</a>

I am using Angular so this is where the components selector is added:

<ul class="container">
    <li class="item-list-container oneSec">
        <app-image-item
          *ngFor="let imageEl of galleryList"
          [image]="imageEl"
          (click)="onImageSelect(imageEl.id)">
        </app-image-item>
    </li>
</ul>

Here is the relevant CSS code:

.like-icon {
    color: red;
    position: absolute;
}
Bail P
  • 251
  • 1
  • 5
  • 17
  • do not use absolute, change it using flexbox. – aJaysanity May 15 '20 at 17:33
  • I need to position it absolutely so that the icon overlaps the images. I don't believe the issue is due to the absolute positioning otherwise none of the icons would display. I have tried removing the absolute positioning and used display: flex, justify-content: center and align-content: center on the icon container but this caused the hearts to be sandwiched between the images – Bail P May 15 '20 at 17:45
  • you can overlap icon and images using flex – aJaysanity May 15 '20 at 18:01

0 Answers0