Showing a collection of cards within a dynamic container set up in a 3x3 grid layout to start

In an attempt to showcase cards within a responsive container utilizing bootstrap and django, my goal is to create a 3x3 grid layout on extra-large screens with scrollable overflow that adjusts based on device width. Initially, I experimented with wrapping the cards in a flex container with column layout, but found this solution to be temporary and not ideal. Another consideration was dynamically rearranging the cards through javascript upon window resizing, which although possible, may not be optimal. Alternatively, using technologies like CSS Grid could offer a better approach, although my current knowledge on its functionality is limited. Therefore, what would be the most effective strategy for achieving this desired layout... Here is a visual model I created to illustrate the issue at hand:

https://i.sstatic.net/E4d5v.jpg

PLEASE NOTE: The sample code provided below is meant for clarification purposes only and is not essential to the solution: I am showcasing one card here... imagine having 12.

HTML

<div class="container">
        <div class="scrolling-wrapper d-flex flex-column flex-wrap  align-items-center">
        
                
                    <div class="card">
                        <div class="card-body">
                            <div class="card-img">
                                <img src="{% static 'library/img/attention.jpg' %}" class="history-img" alt="">
                            </div>
                            <h6 class="card-subtitle">
                                Lorem ipsum dolor sit amet, co
                            </h6>
    
    
    
                        </div>
                        <div class="card-footer">
                            <span class=""><i class="fas fa-eye"></i>4093</span>
                            <span class=""><i class="fas fa-thumbs-up"></i>1234</span>
                            <span class="badge bg-primary rounded-pill px-2">#hello_there</span>
                        </div>
                    </div>
               </div>
            </div>
     

CSS

    body * {
    box-sizing: border-box !important;
}
.history-img{
    width: 60px;
    height: 60px;
    object-fit: cover;
    object-position: center;

}

.scrolling-wrapper{
    max-height: 700px !important;
    flex-wrap: wrap !important;
    
}

.card{
    
    width: 20%;
    height: 200px !important;
    margin: 0;
}

Answer №1

Here is a suggestion for you to try:

<div class="container">
        <div class="scrolling-wrapper d-flex flex-column flex-wrap align-items-center">
        
                <div class="card-container">
                    <div class="card">
                        <div class="card-body">
                            <div class="card-img">
                                <img src="{% static 'library/img/attention.jpg' %}" class="history-img" alt="">
                            </div>
                            <h6 class="card-subtitle">
                                Lorem ipsum dolor sit amet, co
                            </h6>
                        </div>
                   //other cards goes here
                     </div>
                        <div class="card-footer">
                            <span class=""><i class="fas fa-eye"></i>4093</span>
                            <span class=""><i class="fas fa-thumbs-up"></i>1234</span>
                            <span class="badge bg-primary rounded-pill px-2">#hello_there</span>
                        </div>
                    </div>
               </div>
            </div>

If you want to style the cards using CSS, you can use the following code snippet:

.card-container{
  display:grid;
  grid-template-columns:1fr 1fr 1fr;
  justify-content:center;
  align-items:center;
  text-align:center;
  grid-gap: ; // this is for the gap between your cards
}

To ensure responsiveness, consider using media queries to adjust the grid-template-columns property based on screen size.

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

Having trouble getting the hover effect to work when selecting a different section of the SVG

In my SVG checkbox design, I have a circle element surrounding a polyline element (which acts as the checkmark). The boundaries of the icon extend beyond the circle, causing hover styles to trigger even when hovering outside the circle. I want to change st ...

Accessing content from a different HTML document

I'm currently working on a project using node.js where I need to take input from a text box in an HTML file and store it in an array. However, I'm struggling with how to achieve this. My ultimate aim is to create a chat application, and I believe ...

Issue encountered: The differ cannot recognize the provided object '[object Object]', which is of type 'object'. NgFor is limited to binding Iterables only

I have been following a tutorial on Ionic created by Paul Halliday, focusing on a shopping list project that utilizes Firebase and Angular. However, I am encountering an error every time I try to run the application: Error: Uncaught (in promise): Error: ...

Executing asynchronous JavaScript code within a Golang request: a comprehensive guide

I am in need of a solution to retrieve the content from dynamically generated pages using ajax on a website, specifically with code written in golang. I have found examples for non-ajax pages but struggling to find one that works for ajax pages. Any guid ...

Creating dynamic elements in JavaScript utilizing Bootstrap cards

Looking for help in integrating Bootstrap cards while dynamically generating elements using JavaScript? I am working on a project where I need to generate a list of restaurant recommendations based on user preferences entered through a form, utilizing the ...

Using Axios with Django CSRF Token

Scenario: I am in the process of creating a full SPA using Vue.js for the front end and Django for the back end. These systems are completely separate, not a hybrid app where the index.html page is served by the back end. Strategy To facilitate communica ...

Code in jQuery or JavaScript to retrieve precise node information for the currently selected form field, text, or image on a webpage

Looking to retrieve specific information about the item that has been clicked on a web page using jquery. The clickable item could be a form element (like a checkbox, text box, or text area) or a section of text within a paragraph, div, list, or image... ...

Having trouble with protractor's sendKeys function when trying to interact with md-contact-chips

Does anyone know how to set a value using sendKeys in Protractor for md-contact-chips? I attempted to use element(by.model('skills')).sendKeys('Java'); but it doesn't seem to be working. Any suggestions on how to approach this in ...

Connecting an HTML box to a JavaScript function for the desired outcome: How to do it?

My goal is to connect the input box with id="b" (located inside the div with id="but1") with a JavaScript function that calculates values within an array. Although my junior logic review didn't detect any issues in the code, what mistakes could I have ...

When a button is clicked in (Angular), it will trigger the highlighting of another button as a result of a value being modified in an array. Want to know the

Currently in the process of developing a website with Angular, I've encountered an unusual bug. The issue arises when using an *ngFor div to generate twelve buttons. <div *ngFor = "let color of colors; let i = index" style = "display ...

"Enhancing Forms with Multiple Event Listeners for Seamless Sub

I'm working on creating a countdown timer with 3 buttons for controlling the timer: start, cancel, and pause. The timer itself is a text input field where you can enter a positive integer. I need to use core JavaScript, not jQuery Start Button: Init ...

What are the optimal practices for handling form processing logic in Django when creating or updating models?

Looking to enhance the efficiency of my Django application by adhering to better coding practices. I often come across the advice to have fat models and thin controllers, especially after realizing that a significant portion of my display logic ended up in ...

Is your Chrome DevTools changing CSS Link files to "Constructed Stylesheet" after you edit the CSS using Inspect Element? Find out how to fix this issue!

This issue relates to CSS files that are initially not identified as constructed stylesheets but end up being displayed as such after editing, rendering the file inaccessible. Specifically in Google Chrome DevTools (last observed in Chrome 86): Whenever ...

The encoding error in the encoding process must adhere to valid encoding standards

I recently developed a basic program that utilizes process.stdin and process.stdout. However, when I executed the program and tried to input a value for stdout, an error message popped up stating "TypeError: 'encoding' must be a valid string enco ...

Display the current status exclusively on the template using StreamingHttpResponse in Django

When using StreamingHttpResponse in Django, I encountered an issue where the current status was being appended to the previous one on the front end. Although I was able to retrieve the current status, it was not displaying as expected. Instead of appendin ...

Attempting to retrieve JSON data and present it in a grid layout

I have a JSON file with the following data: { "rooms":[ { "id": "1", "name": "living", "Description": "The living room", "backgroundpath":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrsU8tuZWySrSuRYdz7 ...

How come my directive is being updated when there are changes in a different instance of the same directive?

For the purpose of enabling Angular binding to work, I developed a straightforward directive wrapper around the HTML file input. Below is the code for my directive: angular.module('myApp').directive('inputFile', InputFileDirective); f ...

Develop a payment confirmation session using Stripe and Node.js

I have set up a POST request using Stripe to handle customer payments let paymentData = { errorMsg:'', key: process.env.STRIPE_PUBLIC_KEY } const session = await stripe.checkout.sessions.create({ payment_method_types: ...

`Why am I having difficulty transmitting HTML content with Node.js through Mailgun?`

I've been facing issues with sending HTML in my emails. To troubleshoot and prevent errors, I've opted to utilize Mailgun's email templates. Although I can successfully send out the emails, the problem arises when I receive them - the HTML ...

Incorporating external json information into an HTML form

How do I go about loading an external JSON file? Please note: External files may be blocked by server settings. Populate forms using local JSON <form id="datas-from-json"> <div class="form-group"> <labe ...