I'm puzzled as to why the banner text for my three images in the slider is only displaying on one of the images, all crammed together

Currently, I am working on an ecommerce project with Next.js. One of the challenges I faced was while setting up my banner page that includes a react-slick slider for images. Initially, when I added just one image, I noticed multiple renderings of it, but upon adding two more images, it displayed all three images as expected. However, when I attempted to add text to each image's banner, I encountered unexpected behavior.

The issue arises where all the text I add is only showing on one image, and no text appears on the other images. Although my code is error-free, making it tough for me to debug this problem.

Here is the snippet of my banner component:

"use client";

import Slider from "react-slick";
import Image from "next/image";
import BannerText from "./BannerText";
import bannerone from "@/images/bannerone.jpg";
import bannertwo from "@/images/bannertwo.jpg";
import bannerthree from "@/images/bannerthree.jpg";
import { PiCaretLeftLight, PiCaretRightLight } from "react-icons/pi";

// Banner component code here

export default Banner;

And here is the snippet of my bannerText component:

import Container from "./Container";
import { motion } from "framer-motion";

interface Props {
  title: string;
}

// BannerText component code here

export default BannerText;

The screenshot showcases how all the text is stacked on one image within the slider, neglecting the other images:

https://i.sstatic.net/6x1bVeBM.png

Answer №1

It seems like the problem lies in positioning BannerText as absolute without specifying its reference parent. The issue arises because the closest parent with a relative position is not the div representing a Slide but Slider instead. This causes the BannerText component to not slide correctly. While there are multiple solutions, the easiest one, considering your current approach, would be to set the direct parent (representing a Slide) to relative. Here's how you can do it:

<Slider {...settings}>
    <div className="relative">  // <-- first Slide
        <Image
        src={bannerone}
        alt="bannerone"
        priority={false}
        className="w-full h-full relative"
        />
        <BannerText title="Outware Picks" />
    </div>
    <div className="relative">  // <-- second Slide
        <Image
        src={bannertwo}
        alt="bannertwo"
        priority={false}
        className="w-full h-full relative"
        />
        <BannerText title="Seasonal Offers" />
    </div>
    <div className="relative">  // <-- third Slide
        <Image
        src={bannerthree}
        alt="bannerthree"
        priority={false}
        className="w-full h-full relative"
        />
        <BannerText title="Best for men" />
    </div>
</Slider>

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

CSS code influencing unintended elements

www.geo-village.com <- Live Example After setting up my main webpage with CSS and PHP files, I noticed an issue with the navigation bar. Despite having a separate PHP and CSS file for the navigation bar items, the Login and Register buttons on the main ...

Arranging Data in AngularJS based on Selected Filter Criteria

I have a filter function that currently only returns the name values in my table. I would like to add options for both ascending and descending sorting to this filter. Progress So Far: I am able to retrieve values from all inputs, including the name and ...

Using variables within the useEffect hook in ReactJS

I am currently working on a project using Reactjs with Nextjs. I am facing an issue where I need to retrieve the value of "Editor" and alert it inside the handleSubmit function. Can anyone help me with how to achieve this? Here is my code snippet, any as ...

What sets apart the concepts of Boolean and boolean when it comes to Typescript?

I would like to understand the distinction between Boolean and boolean in Typescript. Can anyone provide an explanation? ...

The issue with Angular's two-way data binding in a string array is that it is not functioning properly

Can someone help me understand the correct way to use ng-model in an array of strings? I attempted the following: Component.ts toDos: string[] =["Todo1","Todo2","Todo3"]; Component.html <div *ngFor="let item of toDos;let index = index"> <i ...

Changing Parameters in Absolutely Positioned Sections

I have successfully created a fixed header with a higher z-index than the body content, allowing the content to slide underneath it. To position the content div directly below the fixed header, I applied a position:relative and specified a top value. Init ...

Having trouble running the development environment with npm or pnpm due to permission problems

I encounter this issue when running the command without sudo, but everything works fine with elevated permissions. What could be causing this discrepancy? I've searched for similar questions on various platforms and encountered the same problem with b ...

What is the reason behind encountering these errors while trying to run my Gatsby development server?

I'm currently working on the part three tutorial provided by Gatsby on their official website and I've encountered a problem. Upon executing the command gatsby new tutorial-part-three https://github.com/gatsbyjs/gatsby-starter-hello-world I rec ...

When using react-i18next, the key name is shown instead of its corresponding value on display

I am currently working on a React project using different languages, but I have encountered an issue where the key name is displayed in the DOM instead of its corresponding value. The code in index.js appears as follows: // import statements // i18n initi ...

Rendering a page in Next.js for React based on user authentication status

I am currently experimenting with setting up a nextjs index.tsx page that will display a specific component if the user is authenticated, and another one if they are not. While I have successfully rendered the component for non-authenticated users, I am f ...

Permission Error: Client has been denied access to the requested data in the Firebase Database

I have a database named users set up on Firebase. I've configured the following rule to allow read and write access: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { allow read, write: if true; ...

Overflow issue with Mui TabList within a grid container

I have encountered an issue with the tabs overflowing beyond the visible width when wrapped in the TabsWrapper in the code below. I always render the tabs in a similar wrapper and wonder if there is a way to override certain styles in ScrollableTabs to ach ...

react.js function that returns 'undefined'

Having trouble with my class function that returns undefined when I try to use the return value. Main.js: let db = new Database() let username = db.get() return( //returns undefined <p>{username}</p> ) database.js: class Database { [... ...

Optimal method for relocating an element efficiently

I'm currently working on a project where I need to implement horizontal movement for a DOM element. The movement should start on mousedown, continue on mousemove, and end on mouseup. This task is especially challenging due to the site's numerous ...

Tips for removing the Y-Axis entirely from a CanavasJS chart

I'm working with a canvasJS chart and my goal is to completely hide the Y-Axis. I've managed to remove the Y-Axis line and title in this JSFiddle example. I came across these properties to hide the Y-Axis title and line, but I'm struggling t ...

Error: The function concat() is not valid for messagesRef.current

I'm currently developing an app that enables users to interact with AI by asking questions related to the uploaded PDF file. However, I've encountered a problem while interacting with AI on the client side - I keep receiving the error 'TypeE ...

There appears to be no data available from the Apollo Query

I'm facing an issue with the returned data from Apollo Query, which is showing as undefined. In my code snippet in Next.js, I have a component called Image with the src value set to launch.ships[0].image. However, when running the code, I encounter a ...

Modifying the default hover color of a specific row in AgGridReact

How can I eliminate the row color changing behavior in AgGrid tables when a row is selected and hovered over using React? Currently, a default dark gray color is applied when I hover over certain elements of a selected row, which is not desired in my imple ...

What is the reason behind the checkbox event status returning the string "on" rather than true/false?

I have implemented a custom checkbox as a child component within a parent component. I properly pass the ngModel, name, etc., and attempt to update the model with a boolean status (true/false) based on the checkbox status using an EventEmitter. However, t ...

What is the most effective method for generating an object and sending it to the parent component?

Is there a better way to create an object and pass it to a parent component? The code below does the job, but it feels like there is a lot of unnecessary complexity just to handle a simple form with 2 fields. I'm setting up a constructor, listening ...