Angular 6: Implementing a dynamic photo grid using CSS

I am looking to implement a dynamic grid list using Angular 6's *ngFor directive. I have an Array of 105 objects stored in firebase, each with the structure:

{src: 'some url', alt: 'title'}

These objects consist of two types of photos - horizontal and vertical. My goal is to create a section that automatically fills up empty space by utilizing a grid list in CSS3. How can I integrate this with the following code snippet:

<div class="row">
<div class="imageGallery1 " *ngFor="let image of galleryList">
  <a  [href]="image.src" [title]="image.alt">
    <img [src]="image.src" [alt]="image.alt" style="max-width: 300px; max-height: 300px; object-fit: contain; padding-right: 20px;" />
  </a>

</div>

Note: The styles provided are temporary for creating thumbnails.

Is there a way to identify the type of each photo (vertical or horizontal) and automatically sort them accordingly? Please advise if there is an alternative approach to achieving this.

Answer №1

I stumbled upon a solution for grid layout using CSS on a YouTube course.

Check out the tutorial here

Here is the CSS code:

.row {
  display: grid;
  grid-gap: 5px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  grid-template-rows: auto;
  grid-auto-flow: dense;
}
.imageGallery1 {
  text-align: center;
  position: relative;

  & img {
    width: 100%;
    max-height: 510px;
    height: 251px;

  }
}

.vertical {
  grid-row: span 2;
  & img {
    height: 510px;
  }

}

Now, each vertical photo has its own class with grid-row: span 2;

Sharing this in case it can help someone else!

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

Building an Angular docker file is quite time-consuming

I am currently using a Dockerfile to build and run my project. The process of building the Docker image takes around 10-15 minutes, which seems quite long compared to the npm run build command that only takes 2-3 minutes. Do you have any suggestions on h ...

HTML5: Caption for Images: Movement of Image to Following Row

I'm currently working on designing an image gallery and I've encountered an issue with displaying captions below the images. Here's the code I'm using: <div> <figure> <img src="sample-image.png" /> <figcaption> ...

What is the best way to iterate through and keep track of components within an Angular 2

Inquiring about counting components within my angular2 project. I have a total of 15 components - is there a way to loop through all of them or simply display their count? Preferably without involving them in the main app.components.html. ...

The preventDefault function fails to work in Firefox

My input is called shop_cat_edit and I've included the following code. However, it seems to work fine in IE but doesn't work in FireFox. Can anyone help me figure out what's wrong? $('[name=shop_cat_edit]').on('click',fu ...

Issue with JSON/Java not refreshing innerHTML when onClick event occurs

I'm having an issue with my JavaScript code: <script type="text/javascript"> $(document).ready(function() { $('#domaincheckbutton').click(function() { var finalMessage = document.getElementById('finalMessage'); ...

Guide on dynamically loading an external CSS file into a webpage

I am attempting to build a dynamic webpage using external .css files to change the page color scheme. I have provided my code below, however, upon clicking the href, I do not see any changes. Can someone help me identify what might be causing this issue? ...

Sharing cookies between the browser and server in Angular Universal

After trying to integrate cookies in browser and server using the example from this link, I encountered an issue. The cookies do not appear to be shared between the browser and the server. The cookie I set on the browser side is visible, but when I try to ...

How can I create a smaller clickable zone inside a div element?

My task is quite intricate. To begin, I have a hidden wrapper div that fades in when the mouse hovers over it and fades out when the mouse moves away. The next step is to include an image div inside the wrapper div. This image div, larger than the wrapper ...

The script fails to function on elements contained within an infinite scrolling feature

I am facing an issue with my code after implementing infinite scroll. The like script seems to be broken as the page gets refreshed when I try to like a post. Here is the Like-btn script: <script> $(document).ready(function(){ ...

Preventing CSRF, XSRF, and XSS with Angular JWT stored in a Cookie

I'm currently learning Angular and Express, and I am working on implementing a login feature. From what I've gathered, it is recommended to store JWT in cookies with the settings "secure: true" and "httpOnly: true," like so: const jwtBearerToke ...

The div contains a scrollbar

Check out this link for the code Although not visible on the demonstration, when running the code in a regular browser, scroll bars will appear within the parent div. Any ideas on how to eliminate those scroll bars? ...

Create the login/register interface for the personalized ApplicationUser model

(Setting: Visual Studio 2019 v16.4.3) I started a new project "ASP.NET Core Web Application" with the following configurations Using ASP.Net Core 3.1 Including Angular framework Implementing Authentication for Individual User Account (choosing "Store us ...

What are some effective ways to manage repetitive HTML elements like headers and footers in Angular 4?

Within my Angular web project, I find myself using a variety of different headers on multiple pages. Is there a way to streamline this process by coding the header and footer once and having them automatically included in one or more pages? I am looking ...

Generate a hard copy of the data table row without needing to view it beforehand

Here are some records from a table: +--------+---------+-------+----------+--------+ | Name | Address | Phone + Email | Action | +--------+---------+-------+----------+--------+ | Andy | NYC | 555 | <a href="/cdn-cgi/l/email-protection" cl ...

Adjust the CSS within a <style> element using jQuery or javascript

What I aim to accomplish: I intend to dynamically add and modify rules within a <style> tag using JavaScript/jQuery. Reason behind this goal: I am in the process of creating a color scheme editor where changes made by the user should be reflected ...

Angular 2 - 'Undefined' Error when using Http with Promises

I'm still fairly new to Angular 2 and I've been attempting to retrieve data from a JSON file. My approach involves using Http with Promise, however, when I attempt to log the promise variable, it returns as Undefined. post.services.ts import ...

A step-by-step guide to extracting an array from JSON data using Angular 2

Working on an angular 2 app, I've created a service and now I need to extract a specific array from the json data. How can I do this? Here is my service code: getProjects(): Promise<Project>{ return this.getData() .toPromise() .then(respon ...

The A-frame inspector tool is not very useful within the Glitch platform

Just want to preface this by saying that I am completely new to both a-frame and Stack Overflow. Lately, I've been experimenting with A-frame templates similar to the one linked here: When I pull up the inspector for the example above (ctrl-alt-i), ...

Is there a term similar to "Rise above the Rest" in the world of Web Development?

Hey, I've encountered a new issue right now. Currently, I have two elements that are fixed to the top and bottom of the page. However, the elements in between them are overlapping the top element. Even though I tried keeping both elements fixed, th ...

Utilizing CSS3 Columns to control the flow of elements and enforce breaks

Struggling to articulate my question, but I'll give it a shot :D Let's talk about the images: I'm having trouble explaining, I want to align the elements like in the first image, but all I'm getting is the second and third pictures. C ...