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

Two full screen divs aligned side by side using float:left

Looking for a way to create UL or DIV elements where each list item/child div takes up the full screen space (100% width, 100% height) and is floated left for horizontal scrolling. Here's my code, but it's not working as expected: HTML: <htm ...

The DIV refuses to center-align

I am struggling to center a div element. I have tried using margins (margin: 0 auto) and left/right CSS attributes (left: 50%, right: 50%), but the result is not as expected. Can anyone point out where the problem might be? EDIT: The issue I'm facin ...

The element 'mat-slide-toggle' is unrecognized following the import

I'm currently facing an issue with using <mat-slide-toggle>Click me!</mat-slide-toggle> in a component that already has the MatSlideToggleModule imported. Strangely, I'm still encountering an error stating that it's not a recogni ...

Stop the inclusion of the scrollbar in the mat-drawer-inner-container within the Angular mat-drawer Component

Background Story: Working on designing a screen layout that includes the use of a mat-drawer to display a custom component. The challenge arises when the custom component gets nested inside a div (with class="mat-drawer-inner-container") automatically adde ...

What could be causing the whitespace around this element when using SASS from Refills / Bourbon.io?

I've recently started using the impressive SASS framework, Boubon.io created by the talented team at thoughtbot. As I experiment with their supplied templates (known as Refills), I'm finding that Bourbon.io serves as a versatile alternative to po ...

What are some methods for customizing the calendar icon displayed in an input field with type date?

Is there a way to customize the calendar logo without relying on jquery? The desired appearance should resemble the image shown below: https://i.sstatic.net/G06iZ.png input { width: 50%; padding: 8px; border-radius: 10px; ...

Updating Button Text with PHP on WooCommerce

Hi there, I'm trying to find a way to translate a button in my WooCommerce store without using LocoTranslate or any other tools. Is there a PHP function that can help me change the button text without needing an ID? If you want to take a look at the ...

CSS: Overlapping two divs with unique classes and varying margins - Unexpected occurrence or intentional design?

One thing I'm curious about: Will the margins of two different divs merge if they have the same value when intersecting? It appears so! Do paddings not merge when two different divs intersect, even if they have the same value? It seems that way! When ...

What could be the reason for the d-flex class in bootstraps preventing my div from expanding to 100% width?

I have a div where I need to display two elements next to each other: a search input field and the corresponding submit button. My attempt so far was to achieve this using the following code: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn. ...

Calculate values dynamically when styling material-UI components

Utilizing the Material-UI style to define the class. Now, I aim to adjust the height based on the browser's width. Is there a way to dynamically calculate this within makeStyles() or implement a workaround? This snippet below represents what I am t ...

Personalizing the form controls in Bootstrap for selection options

Utilizing Bootstrap's form-control class helps maintain a consistent style for both form input and select option elements. However, when using form-control on select elements, it results in an unsightly drop-down button appearance in Firefox.https://i ...

What is the process for launching my Angular 8 application on an Apache server running Ubuntu 18?

I am looking for a way to showcase my compiled "dist" folder, which was generated on a Windows system using the command "ng build --prod", on an Ubuntu 18 server that is running Apache. Any suggestions on how I can achieve this? ...

Guide on linking an XML reply to TypeScript interfaces

Currently, I am faced with the task of mapping an XML response (utilizing text XMLHttpRequestResponseType) from a backend server to a TypeScript interface. My approach has been to utilize xml2js to convert the XML into JSON and then map that JSON to the Ty ...

Combining Angular with X3D to create a seamless integration, showcasing a minimalist representation of a box

I am brand new to web development, and I am feeling completely overwhelmed. Recently, I decided to follow the Angular tutorial by downloading the Angular Quickstart from this link: https://github.com/angular/quickstart. My goal was to add a simple x3d ele ...

Navigating Angular 2 v3 router - accessing the parent route parameters within a child route

My route is configured as /abc/:id/xyz The abc/:id portion directs to ComponentA, with /xyz being a nested component displayed within a router-outlet (ComponentB) Upon navigating to /abc/:id/xyz, I utilize this.route.params.subscribe(...) (where route is ...

What steps can you take to stop a tab from being inserted if one is already present?

I am facing a simple issue where I need to prevent the insertion of a tab if one already exists. Issue: I have a search bar that displays results in a div with class.result_container_2 when a user inputs a name. Upon clicking on this tab, another tab is i ...

Tips for adding and verifying arrays within forms using Angular2

Within my JavaScript model, this.profile, there exists a property named emails. This property is an array composed of objects with the properties {email, isDefault, status}. Following this, I proceed to define it as shown below: this.profileForm = this ...

The behavior of Material-UI Drawer varies when used on tablets

Encountering some strange issues with the Material-UI drawer component. It's scrolling horizontally on my iPad, while it scrolls vertically on my MacBook and Android Phone. Expected Result on MacBook: https://i.sstatic.net/txBDf.png On my MacBook, it ...

Angular 2: Export Data to CSV and Download

My backend is built in a Spring Boot application where I am returning a .csv file. @RequestMapping(value = "/downloadCSV") public void downloadCSV(HttpServletResponse response) throws IOException { String csvFileName = "books.csv"; ...

Converting Angular 5 select option values to strings is a must

I have set up a basic select connected to a variable like this: <select id="client" name="client" [(ngModel)]="order.clientId"> <option *ngFor="let client of clients" [value]="client.id"> {{ client.name }} </option> </ ...