Tailwind's implementation of CSS Grid allows for the creation of a grid structure where specific cells can be selectively populated

I am currently using Tailwindcss with my Next.js application to showcase multiple images retrieved from a Supabase database in a grid layout. However, I am facing a problem where the images are being displayed in rows instead of columns within the grid when inspecting the page. A visual reference can be seen in this screenshot: https://i.sstatic.net/ArP4n.jpg

The setup involves a component that contains the image, populating a gallery nested within my index.js file. Here is how it's structured:

IMAGE

<a href={img.id} className='group'>
<div className='aspect-w-3 aspect-h-4 w-full overflow-hidden rounded-md bg-gray-200'>

<Image
alt={img.title}
src={img.imageSrc}
width="200"
height="300"
layout="fill"
objectFit='cover'
className={cn('group-hover:opacity-75 duration-700 ease-in-out', isLoading? 'grayscale blur-2xl scale-110':'grayscale-0 blur-0 scale-100')}
onLoadingComplete={() => setLoading(false)}
/>

</div>

GALLERY

<div className="mx-auto max-w-2xl py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl">
      <div className="grid grid-cols-1 grid-flow-row-dense gap-y-10 sm:grid-cols-2 gap-x-6 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
        <div>
          <BlurImage key={img.id} img={img} />
        </div>
      </div>
    </div>

INDEX

 <div className="mx-auto">
    {product.map((img) => (
    <Gallery key={img.id} img={img} />
    ))}
    </div>

My goal is to have all images displayed on the grid, aligned side by side and wrapping naturally to the next row, which should be the default behavior of CSS Grid.

UPDATE: After further examination of the website, I would like to revise my query. As shown in the screenshot, the div containing the grid container has been replicated 5 times (corresponding to the number of items in the database).

If you have any insights on what might be causing this issue or suggestions on how to resolve it, I would greatly appreciate your assistance. Thank you in advance.

Answer №1

Insight

After examining the site, it appears that the grid container div may be duplicated due to the mapping of Gallery.

Could it be possible that only one gallery is required? If so, consider passing product data as props to gallery and using map() solely for the images.

One potential solution could look like this:

<div className="mx-auto">
  <Gallery images={product} />
</div>
<div className="mx-auto max-w-2xl py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl">
  <div className="grid grid-cols-1 grid-flow-row-dense gap-y-10 sm:grid-cols-2 gap-x-6 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
    {props.images &&
      props.images.map((img) => <BlurImage key={img.id} img={img} />)}
  </div>
</div>

Original Point

Upon testing the specified grid styles within a reduced test environment, found at this link, no errors were detected.

Is there a possibility that the code snippet related to "GALLERY" might lack a map() function? It seems necessary for each Gallery instance to have a corresponding set of images to fill the grid container, with the help of BlurImage.

If this assumption holds true, you may want to try eliminating the extra wrapping div around BlurImage, allowing the components to align properly within the grid layout.

GALLERY

// Placeholder example where "images" represent a collection of images passed to Gallery as props

<div className="mx-auto max-w-2xl py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl">
  <div className="grid grid-cols-1 grid-flow-row-dense gap-y-10 sm:grid-cols-2 gap-x-6 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
    {images.map((item) => (
      <BlurImage key={img.id} img={img} />
    ))}
  </div>
</div>

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

The text does not automatically move to the next line

How can I make the content in this form section wrap to the next line in a list-item and overlap the width of the div content? The second line, particularly where it mentions Security Question two This is my HTML & CSS: <ul class="o-pf-list o-pf- ...

The iPhone encountering issues with Safari's interpretation of @media queries

When it comes to my website on a desktop screen, the body text should not be at the top of the page. However, on an iPhone, it must be displayed at the top. I've created a class with empty paragraphs to control the display on and off, but this class s ...

NextAuth: JWT callback that returns an object

I've been working on a project using Next.js (11.1.2) + NextAuth (^4.0.5) + Strapi(3.6.8). The Next Auth credentials provider is functioning correctly. However, I need to access certain user information using the session. I attempted to do this by ut ...

Problem with transitioning to a different page on Next.js

I am having trouble navigating to a different page in Next.js using the router.push function. The goal is to route to "example.js" by utilizing a variable called ChangePage, which leads to a single div element on that page. However, despite following the ...

My code written using Visual Studio Code is not displaying properly when I view it in my browser

I have been following along with a tutorial series that can be found at this link. This link will take you to the third video in the series, but I have also followed and programmed alongside the first and second videos. After installing Visual Studio Code ...

Tips for organizing a Bootstrap 4 menu overflowing with elements

I'm struggling to figure out how to organize a Bootstrap 4 menu with numerous links. Currently, when I include too many links, the navbar disregards the container and expands its width beyond the container. Here is an image for better clarification: ...

Exclude babel.config.js from being processed by Next.js

Currently, I am working on a Next.js application and I need to customize Babel in order to run my Jest test suite. The issue I'm facing is that when I configure the babel.config.js file, Jest runs successfully but Next.js also picks up this configurat ...

Struggling to include a CSS link to the file, but encountering failure due to a space within the path

The path to the stylesheet is located at C:\Users\abc xyz\Downloads\link-to-a-stylesheet\css. The editor highlights the section after abc in green, but unfortunately, it is not functioning as expected. ...

Ensure that all divs have the same height and padding when resizing

I have 3 divs nested within a parent div. My goal is to dynamically set the height of all the child divs to match the height of the div with the maximum height, even when the screen resizes due to responsiveness. Below is my HTML structure: <div class ...

What steps do I need to follow in order to replicate the layout shown in this

I am struggling with creating a layout in CSS that resembles the one shown in this photo: enter image description here Here is the HTML structure I have, but I can't figure out how to style it properly. <ul class="list"> ...

The height of divs spontaneously changes after resizing without any instructions

I am developing a jQuery function to vertically center an element. The function is triggered on load and here is the code: JQuery var $window_height; function Centerize(content) { content.css('margin-top', (($window_height - content.height( ...

The `@import` statement fails to load styles even when the URL is perfectly accurate

I am attempting to implement CSS styles. @import url("http://mydomain.com/theme/css/reset.css") However, it seems that the styles are not being applied. When I access through the browser, I can see all the CSS rules loading. What am I doing incorrectly ...

Foundational 5 Grid Shuffle Shift

I am currently utilizing Foundation 5 and am aiming to create a unique DIV layout on a mobile display: -------------------- | A | -------------------- | B | -------------------- | C | -------------------- | ...

Click the button to trigger the pop-up

After creating a photo gallery using a plugin, my goal is to display this gallery when the user clicks on my homepage button. I am unsure how to make this happen and would appreciate any assistance. Below is my button code: <div class="ow-button-base ...

Is there a way to customize the color of the collapsible menu?

I am currently delving into Bootstrap to enhance my skills. I decided to utilize the example navbar provided in the documentation: <nav class="navbar navbar-expand-lg navbar-light bg-primary"> <div class="container-fluid"&g ...

Obtaining the accurate offsetTop and offsetLeft values for an element following a CSS3 rotation

Is there a method to accurately determine the offsetTop and offsetLeft values of an element post-transform rotation? Are there any lesser-known element properties that could be helpful in this scenario? Attached is an image that can provide further clari ...

Steps for choosing an image and embedding it within a div element

Upon loading the site, an image is displayed with the following code: <img id="some_Image" src="some_source"> However, I am looking to avoid requesting this image again from "some_source". This is because calculating the image can be resource-inten ...

How can I fix the issue with border-radius not displaying correctly in tcpdf and how can I ensure the text is shown on

Currently, I am utilizing tcpdf to showcase a circle and text together in a PDF. Despite my attempts with the code below, the border-radius attribute is not functioning as expected: Upon implementation, I obtained the following result: The desired outcom ...

Struggling with sluggish performance on a certain project within VS Code

My experience with VS code has been excellent over the years, but I recently encountered a problem in one of my projects that caused a significant slowdown in performance. Strangely, other projects are working fine without any issues on VS code. I suspect ...

How can you turn a SWFObject into a clickable link?

Is there a way to create a clickable link using a .swf flash file with swfObject? I want the entire video to be clickable, but I'm struggling to figure out how to do it. If you take a look at this example here: , you'll see that they were able ...