Angular 2 ngFor with a customizable Bootstrap 4 grid that adjusts accordingly - the perfect

Is there a way to make elements generated by *ngFor in Angular 2 responsive?

I am using the Bootstrap 4 grid system with flex properties in my Angular 2 application, and this is the code I have:

<div class="outlet container">
<div class="row itemsBlock">
   <div *ngFor="let item of items" class="itemRender">
        <img class="itemImage" src="{{item.image}}" />
        <span class=itemitle">{{item.title}}</span>
   </div>
</div>

I would like my items to be rendered responsively as follows:

3 divs in a row on large and medium displays

2 divs in a row on small displays

1 div in a row on extra-small displays

Answer №1

When it comes to looping over the items collection, you can utilize classes such as xl, lg, md, and sm along with the col-size-number (like col-xs-12) class on the same row. Bootstrap will automatically apply the appropriate class based on the screen resolution.

Syntax Example:

<div class="row itemsBlock">
   <div *ngFor="let item of items" class="col-md-4 col-sm-6 col-12">
        <img class="itemImage" src="{{item.image}}" />
        <span class=itemitle">{{item.title}}</span>
   </div>
</div>

Important Note: The grid system in Bootstrap v4 offers five tiers of classes: xs (extra small), sm (small), md (medium), lg (large), and xl (extra large). You can mix and match these classes to create more dynamic and flexible layouts.

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 causing this CORS error in my Angular request?

I currently have a Controller implemented in Angular 4 that makes a request to the NBA API Stats. When I test this request in Postman, I can see all the data without any issues. However, when I execute the same request in my Angular application, I encounte ...

When attempting to duplicate a project from Bitbucket and working in VS Code, I encountered several errors and warnings while running npm install

I have a project on Bitbucket that I'm trying to clone. The project is quite old, about 3 years old, so some packages may be outdated. However, when I run npm install, I am seeing a lot of warnings and errors. Additionally, the project was originally ...

Overflow due to cascading style sheets

THE ANSWER TO THIS QUESTION HAS BEEN PROVIDED In regards to this particular div that contains two unordered lists, I am seeking a solution where these lists can be positioned side by side instead of above or below each other. I have attempted various met ...

Apply a style to the div element that contains a TextInput component

As a beginner in the world of React and Material UI, I am currently working with Material UI version "1.0.0-beta.17", React 15.6.2, styled-components 2.0.0, and styled-components-breakpoint 1.0.1. Within a div element, I have two TextInput fields. const ...

Image not updating in Angular due to issues with AJAX requests

Here is the code snippet I am currently working on: <body lang="en-US" ng-app="socket-server" ng-controller="imageValidationController"> <div class="image-panel"> <h1>Images Found:</h1> <div class="image-list ...

issue with accessing the code through the web browser

Currently, I am developing a web application using ASP.NET MVC5. I have been coding and pushing my work to GitHub. However, I recently encountered an issue where I can no longer view my application on the browser. The "View in browser" option has disappear ...

The useNavigate function in React is causing an error due to its absence

In the past React version, Redirect could be used to switch from one page to another based on a certain condition. However, with v6, Redirect is no longer functional. import React, {useState, Redirect, useNavigate} from 'react'; import './Ap ...

Displaying the information from a nested array of objects in an HTML table through iteration

In the code snippet below, there is an input with a nested array of objects. The main array of objects is called summary and within it, there's a nested array called run_type. let input = { "summary": [ { " ...

Leveraging Ignorable Fields in Angular 2 Reactive Forms

Can Angular 2's reactive forms support adding ignorable fields? For example, consider the following Form: this.form = new FormGroup({ subTasks: new FormArray([]), }); Each subTask requires user input and the solution is stored in the FormArray. ...

Encountered error message: "Cannot assign argument of type '() => () => boolean' to parameter of type 'EffectCallback'"

I recently started working with TypeScript. I encountered an issue when attempting to utilize useEffect in TypeScript within a React context, Error: Argument of type '() => () => boolean' is not assignable to parameter of type 'Effec ...

End node.js once and for all

After starting my server using forever start start.js It ran normally. However, when I attempted to stop it with forever stopall The server was removed from forever list as expected Nevertheless, upon running lsof -i tcp:3000, my server still showed u ...

Troubleshooting: CSS Animation Not Showing up on Screen

When I was attempting to create a JavaScript game in HTML, I encountered a problem. Despite ensuring that the syntax was correct and conducting some research online, the animation refused to display. No matter how many times I tried, it just would not work ...

Modify the view to display the router outlet as a sidebar

Hello, I am trying to figure out why I am unable to access a child route in my application. I have a sidebar where I want to display a list, and if I want to add or edit an item, I would like the view to change within the sidebar from the list to a form a ...

How can I apply styling to Angular 2 component selector tags?

As I explore various Angular 2 frameworks, particularly Angular Material 2 and Ionic 2, I've noticed a difference in their component stylings. Some components have CSS directly applied to the tags, while others use classes for styling. For instance, w ...

Navigating through Sails.js: A comprehensive guide on executing test cases

Being a beginner in sails, node, and js, I may be missing out on some obvious steps. My environment includes sails 0.10.5 and node 0.10.33. Although the sails.js documentation covers tests in , it does not provide instructions on how to actually execute ...

Stop images from flipping while CSS animation is in progress

I've been developing a rock paper scissors game where two images shake to mimic the hand motions of the game when a button is clicked. However, I'm facing an issue where one of the images flips horizontally during the animation and then flips bac ...

Complex React context information stored in sessionStorage

Within my React app, I am currently utilizing a context object to store user information. export const SessionContext = createContext(null); export const SessionContextProvider = ({ children }) => { console.debug("RTS Break SessionContextProvide ...

What is the correct way to use Observables in Angular to send an array from a Parent component to a Child

Initially, the task was to send JSON data from the parent component to the child component. However, loading the data through an HTTP request in the ngOnInit event posed a challenge as the data wasn't being transmitted to the child component. Here is ...

Steps for Integrating a Web Service Reference in NodeJS

Can a Web reference be added to a NodeJS project similar to how it's done in .NET framework Web API Projects? Essentially, the NodeJS API project will serve as a middleware between the Front End and an XML Web service. The XML Web service is a secure ...

Can one utilize Javascript/Angular to listen for a 'request sent' event trigger?

Is there a method in a Javascript/Angular application to intercept a 'request-sent' event triggered by the browser right after the request is sent out? Our goal is to manage and prioritize the order of outgoing requests, potentially sending each ...