Viewing the photo container before uploading while having text overlap

I'm encountering an issue where the image previews are overlapping with the text in another div.

Here are the screenshots: the first one shows how it looks before the preview, and the second one shows what happens when images are added: https://i.sstatic.net/ZSHcU.png

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

You can see that they are overlapping with the text content.

It's worth noting that I am using next.js and tailwindcss for this project.

Below is the code snippet causing the issue:

 <div>
        <div className="font-semibold text-[22px] mt-[48px] mb-[16px]">
          Photos
        </div>
        <div className="mb-[24px] text-[16px]">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
          eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
          enim ad minim veniam, quis nostrud exercitation ullamco laboris
          nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
          reprehenderit in voluptate velit esse cillum dolore eu fugiat
          nulla pariatur. Excepteur sint occaecat cupidatat non proident,
          sunt in culpa qui officia deserunt mollit anim id est laborum.
        </div>
        <div className="w-[653px] h-[259px]">
          <DragDropUpload />
        </div>
      </div>

      <div>
        <div className="font-semibold text-[22px] mt-[48px] mb-[16px]">
          Pink Slip
        </div>
        <div className="mb-[24px] text-[16px]">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
          eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
          enim ad minim veniam, quis nostrud exercitation ullamco laboris
          nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
          reprehenderit in voluptate velit esse cillum dolore eu fugiat
          nulla pariatur. Excepteur sint occaecat cupidatat non proident,
          sunt in culpa qui officia deserunt mollit anim id est laborum.
        </div>
        <div className="w-[653px] h-[259px]">
          <DragDropUpload />
        </div>
      </div>

The DragDropUpload component handles upload logic, here's the relevant code:

    import { useState } from "react";

    const DragDropUpload = () => {
      const [files, setFile] = useState<any | []>([]);
      const [message, setMessage] = useState<any | null>(null);
      const handleFile = (e: any) => {
        setMessage(null);
        let file = e.target.files;

    for (let i = 0; i < file.length; i++) {
      const fileType = file[i]["type"];
      const validImageTypes = ["image/jpeg", "image/png"];
      if (validImageTypes.includes(fileType)) {
        setFile((prev: any) => {
          return [...prev, file[i]];
        });
      } else {
        setMessage("Only images are accepted");
      }
    }
  };

  return (
    <>
      <div className="flex justify-center items-center px-2">
        <div className="h-auto">
          <span className="flex justify-center items-center bg-white text-[12px] text-red-500">
            {message}
          </span>
          <div className="h-[259px] w-[653px] border-2 border-dashed border-gray-400 overflow-hidden relative items-center rounded-md cursor-pointer">
            <input
              type="file"
              onChange={handleFile}
              className="h-[259px] w-[653px] opacity-0 z-10 absolute"
              name="files[]"
              multiple
            />
            <div className="h-[259px] w-[653px] bg-white absolute z-1 flex justify-center items-center top-0">
              <div className="flex flex-col">
                <span className="text-[16px] mb-[2.5px] ">{`Drag and Drop here`}</span>
                <span className="text-[16px] ml-[67px] mb-[8.5px]">or</span>
                <span className="text-center text-[16px] w-[135px] h-[39px] p-[7px] ml-2 rounded-full bg-black text-white ">
                  Select file
                </span>
              </div>
            </div>
          </div>
**// IMAGE PREVIEW IS HAPPENING HERE !!!!!!!!**
          <div className="grid grid-cols-5 w-[659px] gap-[10px] mt-[24px] ">
            {files.map((file: any, key: any) => {
              return (
                <div
                  key={key}
                  className="h-[117px] w-[117px] flex justify-between rounded-lg bg-white"
                >
                  <div className="gap-2">
                    <div className="h-[117px] w-[117px] ">
                      <img
                        className="h-[117px] w-[117px] rounded-lg"
                        src={URL.createObjectURL(file)}
                      />
                    </div>
                  </div>
                </div>
              );
            })}
          </div>
        </div>
      </div>
    </>
  );
};

export default DragDropUpload;

I would appreciate any assistance in resolving this issue as I'm unable to figure it out on my own.

Answer №1

After some investigation, I finally found the solution...

This is the exact change needed in order to make it work:

            <div class="w-[653px] h-[259px]">
          <DragDropUpload />
        </div>

It should be updated to this:

            <div class="w-[653px] h-auto">
          <DragDropUpload />
        </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 absence of a defined window - react-draft-wysiwyg integration with Next.js (SSR) is causing issues

Currently, I am in the process of developing a rich text editor that is used to convert plain HTML into editor content using Next.js for SSR. While working on this project, I encountered an error stating "window is not defined," prompting me to search for ...

Invoke index functions within a component

I have a widget/component written in Angular 4 within the index.html file. Before and after this angular app, there are various HTML elements due to the nature of it being an additional component for the website. The head section of the index file include ...

Unlocking the power of asynchronous methods within the useEffect() hook

When attempting to fetch an API within a useEffect(), I encountered the following error: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. Here is the code snippet that caused the error: -API being fetched: ex ...

Is it optimal to count negative indexes in JavaScript arrays towards the total array length?

When working in JavaScript, I typically define an array like this: var arr = [1,2,3]; It's also possible to do something like: arr[-1] = 4; However, if I were to then set arr to undefined using: arr = undefined; I lose reference to the value at ...

How come CSS styles are not being applied to forms in AngularJS?

When attempting to apply CSS styles to a form in order to indicate invalid input, I encountered an issue. Even after using the important tag, the styles did not change. I created a dynamic form from JSON and now need to validate it. Following a suggestion ...

The Markdown formatting tool isn't displaying code snippets and tables properly

Markdown for Beginners --- title: 'Getting Started with Markdown' date: 'April 1, 2022' excerpt: 'An introduction to Markdown syntax' cover_image: '/images/posts/start-markdown.png' --- # Introduction to Markdown M ...

Front-end and back-end seamlessly integrated in Next.js

I am new to this area and curious about whether it's better to include an API within my project or have a separate back-end integrated. I understand that having a separate backend means paying for two hosting services, whereas incorporating it within ...

How to iterate through two arrays using AngularJS ng-repeat

I have been attempting to create a specific layout by iterating through two arrays However, the output I am receiving from the ng-repeats does not match my desired view Below is the current code that I am working with: $scope.properties = ["First name", ...

Failed to execute test suite in React and Jest framework

While working on updates for our existing project, I encountered an error that is causing some of the tests to fail: FAIL src/components/changelog/__test__/ChangeLogOverView.test.tsx ● Test suite failed to run TypeError: Cannot create property & ...

I encountered a problem when trying to set up ngx-Spinner version 8.0.3

I need help implementing a spinner loader in my app. I have followed the instructions provided at [ https://www.npmjs.com/package/ngx-spinner ] and successfully installed it. However, when trying to import and add it to "imports", I encountered the follow ...

Sending AJAX Responses as Properties to Child Component

Currently, I am working on building a blog using React. In my main ReactBlog Component, I am making an AJAX call to a node server to get back an array of posts. My goal is to pass this post data as props to different components. One specific component I h ...

Contrast between utilizing and publishing, demanding and bringing in within Express

I have recently started learning Typescript and Express. I have a simple exported function that looks like this: export function testFunction(req: any, res: any) { console.log(req.body); return res.status(200).send('OK'); }; And ...

What is the best way to make a drop down menu list appear when I click on the parent li, and then show the sub li using JavaScript?

I have a code that includes an image, HTML, and CSS code. Can anyone please tell me how I can set up a drop-down menu list to open the sub <li> elements when I click on a parent <li> using JavaScript? You can see the appearance of the code in t ...

Is there a way for me to retrieve the widths of all child elements within an HTML document?

I have been working on a JavaScript (jQuery) function to calculate the maximum width of all child and children's-child elements within a specific div element. Here is the code I have written so far: function setBodyMinWidth(name){ var max = 0; $(nam ...

Obtaining the URL path for a ReactJS project that utilizes NextJS instead of React-Router

Having some trouble with fetching URL/Path in my code for class components. It seems like the issue might be related to using nextJS(9.3.0) instead of react-router. fetch_window_URL = () => { let ddd = window.location.href; console.log(`URL is ${ddd ...

Tips for managing variables to display or hide in various components using Angular

In this example, there are 3 main components: The first component is A.component.ts: This is the parent component where an HTTP call is made to retrieve a response. const res = this.http.post("https://api.com/abcde", { test: true, }); res.subscribe((r ...

The fonts appear differently when working on a Mac but show up as Times New Roman when displayed on Windows in development

Currently, I am utilizing react combined with nextjs for server-side rendering and bootstrap. Within my component, I have integrated bootstrap via a CDN: <Head> <title>{title}</title> <meta charSet="utf-8" /> < ...

When navigating using the next and back buttons, the active state in Angular is automatically removed

Looking for some assistance with my quiz app setup. Each question has True/False statements with corresponding buttons to select T or F. However, when I click the next/back button, the active class is not being removed from the previous selection. As a beg ...

Suggestions for altering the CSS styles of my Swiper slides (currently utilizing v10.3.1)

Currently, I am utilizing the Swiper plugin on my website built with React and Next.js. However, I am looking to customize the bullets and buttons of the slider. I have attempted following some video tutorials without much success. Is there anyone who ca ...

Sending a POST request to Mailchimp via Express using React: A step-by-step guide

I'm currently working on a project where users can sign up for a new membership through a form in React and have their information added to the Mailchimp member list via my Express server. However, I've encountered a CORS error and am unsure if I ...