Button located beneath or above each individual image within the *ngFor loop

With the *ngFor loop, I am able to populate images but now I want to include a button below or on each image. Unfortunately, my CSS knowledge is limited. Below is the code I have:

HTML Code

    <div class="container">
              <div *ngFor="let img of imageData">
                <p [hidden]="true">{{img.Id}}</p>
                <img class="original" [alt]="img.Name"
                     src="https://localhost:44349/{{img.ImagePath}}"
                     width="350" height="350"/>
                <button type="submit" (click)="deleteImage()" class="btn btn-danger"><i 
                    class="far fa-trash-alt"></i>
                  Remove
                </button>
              </div>
            </div> 

CSS

.container {
  position: relative;
  text-align: center;
}

.original {
  width: 250px;
  height: 250px;
  float: left;
  margin: 1.66%;
  transition-duration: 0.3s;
  border-radius: 15px;
} 

Answer №1

Here is the solution you've been searching for.

.container {
    /* position: relative;*/
    text-align: center; 
    display: flex;
    flex-direction: column;
}

.original {
    width: 250px;
    height: 250px;
    float: left;
    margin: 1.66% auto;
    transition-duration: 0.3s;
    border-radius: 15px;
}

.content {
    display: flex;
    flex-direction: column;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<div class="container">
    <div class="content">
        <p>Image Id</p>
        <img class="original" src="https://www.w3schools.com/bootstrap/cinqueterre.jpg" width="350" height="350" />
        <button type="submit" class="btn btn-danger"><i class="far fa-trash-alt"></i>
            Remove
        </button>
    </div>
    <div class="content">
        <p>Image Id</p>
        <img class="original" src="https://www.w3schools.com/bootstrap/cinqueterre.jpg" width="350" height="350" />
        <button type="submit" class="btn btn-danger"><i class="far fa-trash-alt"></i>
            Remove
        </button>
    </div>
</div>

To use dynamic images in Angular, your template should look like this:

<div class="container">
    <div class="content" *ngFor="let img of imageData">
        <p [hidden]="true">{{img.Id}}</p>
        <img class="original" src="https://localhost:44349/{{img.ImagePath}}" width="350" height="350" />
        <button type="submit" class="btn btn-danger"><i class="far fa-trash-alt"></i>
            Remove
        </button>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for assigning a CSS class to a div element that is generated by react's render() function?

In React, I am encountering an issue where the css class I want to set on the div returned from render is being removed. This problem even persists when I try nesting another div inside the first one and setting the class on the enclosed div. Has anyone ...

How can Angular 2 populate forms with data retrieved from a promise in a database?

I'm currently navigating through the world of Angular and Firebase, and I’ve hit a roadblock when it comes to populating my forms with data from Firebase promises. Understanding how to work with promises versus observables is also proving to be a ch ...

Implementing a video pause event trigger from a function in Angular2

Here is the content of my player.component.html: <video width="320" height="240" autoplay autobuffer [src]="videoSrc" (ended)="videoEnd()"> Your browser does not support the video tag. </video> <button (click)="pauseOrPlay()">pause/play ...

Creating virtual hover effects on Android browsers for touch events

My Wordpress website is currently utilizing Superfish 1.5.4 to display menu items. The menu on my site includes several main menu items, which are clickable pages, and hovering over these main items should reveal sub-menu options. When I hover over a mai ...

Tips for achieving horizontal alignment of headers

My webpage has two headers positioned as 'CompanyName' on the top left and 'Date' at the top middle but I am struggling to align them horizontally. I attempted to enclose them inside a div element, however, this did not work. Can someon ...

Enhancing user experience with dynamically resized Jumbotron images based on screen sizes in HTML

I am experiencing an issue with the jumbotron images on my website where they become increasingly zoomed in as the screen size decreases, and are extremely zoomed in on mobile devices. Is this a normal behavior of jumbotrons? I do understand that the image ...

How to update an array in Angular using ngModel and ngFor

I am attempting to display an array's values on a form and then allow for updating those same values in the array (using name="todos{{i}}" within the <input> tag does not work as it turns it into a string instead of an array). The curr ...

Choose items that do not contain ::before or ::after pseudo-elements

I am looking to apply a specific font style to all text on a page except for Font Icons (specifically Font Awesome) which do not share a common class. In order to achieve this, I need to target elements in one of the following ways: Elements that do not ...

Tips for removing the splash screen in Ionic 2

I've made changes to the config.xml file by setting the value of the splash screen to none. As a result, the splash screen no longer appears. However, I'm now encountering a white screen instead. Is there a way to prevent this white screen from a ...

How can I make CSS images appear beside specific links?

Currently, I have implemented the following CSS: .entry a { padding: 2px 0 0 8px; background: transparent url(images/link_arrow_light.gif) left top no-repeat; text-decoration: underline; } It is functioning correctly, but the image is being added t ...

Exploring Angular 4: Iterating Over Observables to Fetch Data into a Fresh Array

Context Currently, I am in the process of developing a find feature for a chat application. In this setup, each set of messages is identified by an index. The goal of the `find()` function is to retrieve each message collection reference from the `message ...

Wrapping an anchor tag with a div in Codeigniter

Can a div tag be used inside an anchor function? I have a div with the following CSS: #first{ opacity:0; } Now, I want to include it in my anchor element. Here is the code snippet: <?php if(is_array($databuku)){ echo '<ol>&l ...

An image that is in motion at an inappropriate time

My website has run into an issue. Within the navigation bar, there are two unordered lists containing list items and nested ul tags with images in some of the list items. When applying animations, the image moves along with the tabs. Here are visual exampl ...

What is the best way to alter an Rxjs event in order to track pressed keys?

I found a helpful solution for hotkeys using this RXjs method. In my setup, I am using the condition below to detect leftShift + m keys: const toggle$ = shortcut([KeyCode.ShiftLeft, KeyCode.KeyM]); The issue I'm facing is that it only triggers when ...

Creating a Navigation Bar using the Flexbox property

As a beginner, I attempted to create a navbar using flex but did not achieve the desired outcome. My goal is to have: Logo Home About Services Contact * { margin: 0; padding: 0; font-family: ...

Why does the styling of the inner Span adhere to the style of the outer Span?

How can I adjust the opacity of the color "blue" to 1 in the code snippet below? <!DOCTYPE html> <html> <body> <p>My mom's eyes are <span style="color:blue;font-weight:bold;opacity:0"> <span style="color:blue;fo ...

"Is it possible to add an entire object to formData in one

I am looking to send both an image list and product data to an ASP.net api using formData. I have successfully sent the images, but now I am struggling with appending the entire object. I have come across some methods in JS like JSON.stringfy(object) or Ob ...

Center-aligned video text overlay that adapts to different screen sizes for a responsive design

I am looking to showcase a full-width video with overlay text that is perfectly centered both vertically and horizontally on the video. The centering should adapt to changes in viewport width so that it remains centered at all times. Additionally, I would ...

Implementing Angular 2 - Steps to ensure a service is accessible within the app module

I'm running into an issue trying to utilize a function within a service that I believed was globally accessible. The service in question is named SavedNotificationService: import { Injectable } from '@angular/core'; @Injectable() export cl ...

Trouble with highlighting the chosen menu item

I have been attempting to implement this code snippet from JSFiddle onto my website. Although I directly copied the HTML, used the CSS inline, and placed the Javascript in an external file, the functionality does not seem to be working properly. Feel free ...