Tips for displaying three divs in one row and three divs in another row

I'm aiming for a design with 3 divs in one row and another 3 in the next, like this

But what I currently have is different. Can someone assist me in achieving the desired layout?

MY HTML :

    <div class="category-food">
        <div class="food-item" *ngFor="let art of meals">
            <img class="card-img-top center" [src]="art.strMealThumb" style="max-width:300px;" role="button">
            <div>
                <h1 class="content-text">{{art.strMeal}}</h1>
            </div>
        </div>
    </div>

STYLE SHEET :

I've attempted to use the following styling to achieve the desired look, but it hasn't worked as expected

    .category-food {
      display: flex;
    }
    
    .category-food .food-item {
      align-items: center;
      margin: 20px;
      width: 100%;
      border: 1px solid grey;
    }
    
    .card-img-top {
      display: block;
      margin-left: auto;
      margin-right: auto;
      width: 50%;
      border-radius: 6px;
    }
    
    .content-text {
      font-size: 24px !important;
      text-align: center;
    }

Answer №1

To achieve the desired layout with 6 instances of the specific .food-item class representing individual divs, you can utilize the display: grid; property on the parent container .category-food that contains these div elements.

You can accomplish this layout by including the following CSS snippet:


    .category-food {
      display: grid;
      grid-template-columns: auto auto auto;
    }
  

By applying the above CSS code and replicating the .food-item div six times (as per the requirement), you will see the intended layout.

// more content here...

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

In Typescript, an interface is defined where the "id" property is required to be a number, while all other properties must be of

I am in need of creating an interface to represent data received from the server, where the id is a number and all other properties are strings. This is what I attempted: interface AnyChartsData { id: number; [key: string]: string; } However, I enco ...

ng2-order-pipe fails to apply sorting when objects are added or removed

I have set up my application to display a div for each object in an array, utilizing the ng2-order-pipe to arrange them accordingly: <div class="patients-container" (dragover)="allowDrop($event)" (drop)="onDrop($event)"> <div class="patient-box ...

Learn how to send or submit data using the Form.io form builder

I am currently working on a dynamic drag and drop form builder, and I'm struggling to figure out how to log the data from the form. Below is the component.html file where I am implementing the drag and drop form: <div> <form-builder ...

Adjusting the letter spacing of individual characters using HTML and CSS

Is there a way to set letter-spacing for each character with different sizes as the user types in a text box? I attempted to use letter-spacing in CSS, but it changed all characters to the same size. Is there a possible solution for this? Here is the code ...

"Restricting the height of a DIV container based on the size

Struggling with CSS as I try to get my #wrapper DIV to adjust its size based on its contents. I've experimented with 100% height and min-height, but nothing seems to work. Could it be related to relative versus absolute positioning? Here's a snip ...

Customizing the appearance of a JavaScript countdown timer's output on an individual basis

I am currently working on customizing the appearance of a JavaScript date counter. My goal is to style the days, hours, minutes, and seconds individually. Ideally, I want each unit to be right-aligned within its own div, with specific left and top absolute ...

p-menu fails to appear

I'm currently experimenting with Primeng and Angular 2 to put together a basic menu. Take a look at my code snippet: import {Component, OnInit} from '@angular/core'; import {Menu, MenuItem} from 'primeng/primeng'; @Component({ ...

AngularJS input range is written inside the bubble that crosses over the screen

Is there a way to write inside the bubble of the range slider? I have adjusted the design of the range slider and now I simply want to display the number inside the bubble: Please see image for reference I aim to display the number inside a circle. What ...

What advantages does NgRx offer that Signal does not provide?

Signals are a recent addition to the Angular framework. In comparison to Signals, what unique benefits does the NgRx component store or other state management options provide? Are there any functionalities offered by the NgRx component store that cannot ...

Tips for dynamically injecting HTML content in an Angular web application

I'm currently working on an angular website dedicated to a specific book. One of the features I want to include is the ability for users to select a chapter and view an excerpt from that chapter in HTML format. However, I'm facing a challenge wh ...

Is feature recognition possible in a jQuery plugin?

Can I integrate a tool similar to Modernizr into my plugin? I want to be able to test for specific CSS3 properties without starting from scratch. ...

The ngb-datepicker feature seems to be experiencing issues when used within an Angular Material input field (

How can I integrate ngb-datepicker into a material Input? While I have successfully applied the datepicker to the mat input, I am facing an issue with the month and year dropdowns. I attempted the following snippet : <mat-form-field> <input matI ...

Excluding properties based on type in Typescript using the Omit or Exclude utility types

I am looking to create a new type that selectively inherits properties from a parent type based on the data types of those properties. For instance, I aim to define a Post type that comprises only string values. type Post = { id: string; title: string ...

Partial button clickability issue

There is a puzzling error where the button in the 'red area' is not clickable, and I can't seem to figure out why. Below are images illustrating the issue: https://i.stack.imgur.com/aPfcR.png https://i.stack.imgur.com/v5knZ.png Upon reac ...

The responsiveness of the Bootstrap website is lacking

Viewing the site on mobile @media screen and (max-width: 600px) { .sidebar { width: 100% !important; height: auto !important; } } @ ...

Newly designed Bootstrap 4 input field with search feature positioned off-center on smaller screens

I have successfully positioned an input text next to a button as shown below: While it displays perfectly on a regular computer screen, the alignment gets skewed when viewed on a phone device: This is the functional code I am using: <!-- Add Filer Fo ...

Interactive canvas artwork featuring particles

Just came across this interesting demo at . Any ideas on how to draw PNG images on a canvas along with other objects? I know it's not a pressing issue, but I'm curious to learn more. ...

Connecting Ag Grid with modules

Unable to link with modules as it's not a recognized attribute of ag-grid-angular https://i.sstatic.net/2zwY2.png <ag-grid-angular #agGrid style="width: 100%; height: 100%;" id="myGrid" class="ag-theme-balham" [mod ...

How to adjust the transparency of a background image in a parent div without impacting its child elements? (Using Twitter Bootstrap)

In an effort to enhance the aesthetics of a website, I have been utilizing Twitter Bootstrap. One snippet of my HTML code looks like this: <div class = 'container-fluid bg-1'> <div id ='yield_wrap'> ...

Developing a sophisticated responsive menu using Bootstrap 5 and Flex

I need a responsive menu that always maintains the appearance shown in the image below. Any overflowing content should trigger the addition of a scrollbar: https://i.sstatic.net/Gen7g.png Although my current solution works initially, it fails when additi ...