Is there a way to translate an array into an HTML grid layout?

I am currently working on mapping an array into image sources to create an image gallery. The issue I am facing is that it only maps down one column, and I am unsure how to make it fill the other columns as well. Any suggestions or tips would be greatly appreciated!

Here is the current output:

https://i.sstatic.net/YrTQE.png

My goal is to achieve this layout:

[123]

Below is the code snippet I am using:

<div className="image-grid">
       <SRLWrapper options={options}>
                        {data.home.galleryImage.map((image, index, caption) => (
                              <div className="image-item" key={`${index}-cl`}>
                               <img src={`http:XXX${image.url}`} alt="" class="galleryimg"/>
                               <div class="imgoverlay">
                                <div class="imgtext">zoomie</div>
                              </div>
                              </div>
                        ))  
                        }
      </SRLWrapper>
</div>

Here is the related CSS code:

.image-grid {  
    display: grid;
    grid-template-columns: repeat(3, minmax(100px, 1fr));
    column-gap: 2rem;
  }

  .image-item {
    position: relative;
    width: 100%;
    display: block;
    margin-bottom: 2rem;
    
  }

Answer №1

The key lies in the simplicity of it all. Your display:grid styling is currently only affecting the SRLWrapper component.

To resolve this issue, ensure to assign the className="image-grid" to the parent element of your SRLWrapper component, and then watch as it seamlessly falls into place :)

In the SRLWrapper.js file, you'll find JSX code that dictates what will be displayed. By having just one grid item within your grid container, despite setting it to have 3 columns, you are limiting what the SRLWrapper can display.

A Handy Tip: Always make use of the Developer Console (Ctrl+Shift+I) for debugging purposes in scenarios like these, as it provides a clearer insight into the underlying issues.

Answer №2

Within the stylesheet

grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));

Try replacing autofit with 3 and see if that solves the issue.

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 my cookie script to malfunction?

I'm experiencing an issue with my cookie script on the following website: Upon visiting my site, you'll come across a hidden <div id="popupDiv"> Due to the display: none property in the CSS, it's not visible as intended. However, it ...

Guidelines on isolating the navigation bar from the rest of the webpage

Being new to web development, I am currently working with Django framework in VSCode. My goal is to create a user interface for a web application that features a left side menu and a top navigation bar that says "home page" (see image below). I want all te ...

Metadata pertaining to the duration of blob videos

I have developed a software that processes camera stream video specifically in Firefox. Using the MediaRecorder API, I create a Blob containing video recordings. To save this blob as a video in local storage, I utilize the FileSaver library: FileSav ...

Step by step guide on uploading files using Vue.js and Express.js

Hello there, I am new to Vuejs and Express and I'm looking to practice my skills. Currently, I am attempting to build a User Profile with an image upload feature using Vuejs and ExpressJs but unfortunately, none of the files or text are uploading as ...

One way to eliminate a prefix from a downloaded file path is by trimming the URL. For example, if you have a URL like "http://localhost

As my web app runs on port number, I am looking to download some files in a specific section. However, the download file path is being prefixed with "". <a href={file_path} download={file_name}> <Button variant={"link"}> <b>Dow ...

Issue encountered: ENOENT error - The specified file or directory does not exist. This error occurred while attempting to access a directory using the

I don't have much experience with nodejs or express, but I have an API running on http://localhost:3000. One of the endpoints triggers a function that uses the file system to read a file synchronously. However, when I send a post request using Postman ...

What is the standard way elements are displayed within a box that is positioned absolutely?

My current setup involves setting <body> to be absolutely positioned in order to fill the entire viewport without needing to specify a height: body { width: 100%; margin: 0; padding: 0; position: absolute; top:0; right:0; bottom: ...

Context menu for OpenLayers 3 maps

Is there a way to implement a right-click context menu that displays information about the clicked point? For example, when I right-click on a map, a dropdown menu should appear with options like 'add marker', and it should also show the coordin ...

The content in the html document is not flowing outside a div unless I eliminate the floating property from the div(s)

My goal is to create a page layout with three sections, each floated left based on the device width using media queries in my CSS. I have successfully achieved this, but when I inspect the page using Chrome Developer Tools, I notice that the body is not sp ...

Implementing a hover effect for a link that triggers a pop-up window, similar to Facebook's feature where hovering over a link reveals options such as sending a message

As a rails programmer, I am working on creating a hover pop-up for links in my project. In this particular scenario, I have an array of users being displayed with various details such as user image and name. My goal is to have a pop-up window appear only w ...

Ways to categorize axios call headers

I'm encountering an issue while attempting to send a request via Axios and specifying request headers using types. Unfortunately, I am running into an error. To address this, I have defined an interface called Headers and utilized it to declare a var ...

Creating a bottom bar using React and Material UI

I'm currently working on implementing a footer that will be displayed on every page of my Next.js application. To style this, I am utilizing Material UI. The following component is responsible for defining the layout across all pages of the app: impo ...

I keep receiving an error in Angular JS but I'm unsure of the reason

I've been working on AngularJS and created a basic module and controller. I'm attempting to show the data of an element inside the controller on the HTML view page, but all I see is {{student.name}} and I'm receiving an error message that sa ...

Encountering CORS Issue when attempting to upload a file from an external URL using Angular

I am attempting to upload a file from an external URL, but I keep encountering a CORS error when trying to access the external URL. await fetch(url).then(function (res) { response = res; }).catch(function () { setTimeout(() => { this.toaster. ...

Troubleshooting a Button Problem with CSS in Twitter Bootstrap

Here is the original source (with problem) However, when attempting to replicate the issue in jsfiddle, I am getting the correct result What could be causing this discrepancy? How can I resolve this issue? ...

invoking a controller using a method in JavaScript

As I work on constructing a website using MVC 3 razor, there is a specific scenario that I am currently dealing with: One of the challenges involves a controller method: public ActionResult MyControllerMethod(int parameter){ ''perform some ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...

Best method to generate an element using any jQuery selector string

What I want to accomplish I am looking to create an element that matches any given selector string. Here's a quick example: var targetString = "a.exaggerated#selector[data-myattr='data-here']"; var targetEl = $(targetString); if(!targetE ...

What is the process for inserting a scroll bar within a div element?

   I have recently created a webpage using some divs, along with a bit of CSS and JavaScript. I am struggling to figure out how to add a scrollbar to one of my divs. The code is not overly complex, as it includes both CSS and JavaScript. <html> & ...

Am I using the correct method to parseInt within an if-else statement for Datatable?

Just started working with JS BS Datatables, wondering if this is the correct approach for using parseInt in an if else statement? $(document).ready(function() { $('#myTable').DataTable({ "order": [], "columnDefs ...