The stacking order of React components

I am having an issue with the Z-index in my component-based React app. I currently have a list component that contains items, and I want to adjust the CSS scale and z-index to display one item in front of the others.

The problem arises when the hovered item is displayed on top of the other items in the same list, as well as on top of List Headlines (classic HTML elements, not React components). Unfortunately, the z-index does not work for the other lists.

Item Component

<div className={isHovered ? 'sliderItem active' : 'sliderItem'} onMouseEnter={handleHover} onMouseLeave={handleHoverEnd}>
    <div className="sliderItemThumbnail">
        <SliderHoverLoader isHovered={isHoveredLoader}></SliderHoverLoader>
        
        {props.backDrop ? <img src={`https://image.tmdb.org/t/p/original${props.backDrop}`} alt="" /> : <img src="https://www.kindpng.com/picc/m/18-189751_movie-placeholder-hd-png-download.png" alt="" />}
        
        {trailer !== '' ? 
            <iframe src={`https://www.youtube-nocookie.com/embed/${trailer}?autoplay=1&mute=1`} title="YouTube video player" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe> 
            : ''}
    </div>
</div>

List Component

<div>
    <SliderIndicator sliderIndex={sliderIndex} sliderLength={sliderLength} handleChange={handleSliderDirectChange}></SliderIndicator>
    
    <div className='sliderContainer'>
        <SliderControl direction="left" sliderControlsOff={sliderControlsOff} handleClick={handleSliderDirection}></SliderControl>  
        
        <div className="sliderWrapper" style={{transform: `translateX(${sliderIndex * -100}%)`, transition: `${sliderTransitionOff ? "none" : "all "+sliderDuration+"ms"}`}}>
            {movies.map((movie, i) => (
                <SliderItem backDrop={movie.backdrop_path} title={movie.title} releaseDate={movie.release_date} id={movie.id} key={i}></SliderItem>
            ))}
        </div>
        
        <SliderControl direction="right" sliderControlsOff={sliderControlsOff} handleClick={handleSliderDirection}></SliderControl>  
    </div>
</div>

CSS .active class is simple

.sliderItem {transform: scale(2); z-index: 50}

No other components have the z-index set

This is how it looks without hover: No hover

This is how it looks with hover: With hover

This is how it should look: Desired look

Where could the problem lie if the z-index works over classic

or divs, but not over constructed components?

Answer №1

Resolving the issue with position relative...

UPDATE: It is important for the parent element to have a position relative, as explained in https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

In my scenario, it was the nested div where I was iterating through the items

...<div className="sliderWrapper" style={{transform: `translateX(${sliderIndex * -100}%)`, transition: `${sliderTransitionOff ? "none" : "all "+sliderDuration+"ms"}`, position: 'relative'}}>
  {movies.map ((movie, i)=>
     <SliderItem....

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

Tips for decreasing the height of a cell or row in a React component

Currently, I am incorporating the table component in my React UI using Material-UI. Here is a link to the Material-UI Tables demo. I am looking to adjust the height of the rows or content cells within this table. The content rows are styled in alternating ...

Day Change Triggers React [Native] View Update

I've been working on a React Native component that needs to update itself when the day changes, regardless of user interaction. Is there another method besides using setInterval for this task? If I use setTimeout in my viewDidLoad function with the n ...

Is there a way to develop a login form that retrieves information from a Google Sheet database?

Please help me with a solution. I have developed a registration form which effectively saves users' information in a Google Sheet. However, now I am yearning to create a login form that verifies the stored data and redirects the user to a different pa ...

Tips for enabling the wrap property with autogeneratecolumn set to true

In my grid view, I want to ensure that any text in a column that exceeds the width of the column will either wrap within the column or display on a new line. Below is the code for the grid view: <asp:GridView ID="GridView1" AllowSorting="True" runa ...

Exploring the properties within a MongoDB document using mapping functionality

I am trying to retrieve data from a document using Node.js and encountering an issue where the map operator is returning data with similar names twice. I am wondering if I can use filter instead of map to address this problem. Here is the code I am using t ...

Is the z-index functioning properly for the header call-to-action text on mobile devices, but not on desktop?

The desktop header cta is functioning properly, but when I switch to mobile nothing happens. I attempted to increase the z-index number within the html instead of in the style sheet. This is where my CTA is located in the html: CALL TO ACTION surrounded ...

I'm struggling with getting the state.map function in react.js to display the data correctly

Encountering an issue with my code. Trying to fetch data from the server-side (node.js) and saving it using setState(data), the console.log(this.state.data) displays all the data, but mapping it returns nothing. Interestingly, when creating an object in C ...

Enhancing the Appearance of MUI Date Calendar

I'm in the process of creating a calendar similar to mui's <DateCalendar />, and I want to customize the header from 'S M T W T F S' to 'Sun Mon...' as well as adjust the position of the arrows. Before: https://i.sstat ...

Tips for resolving a double click issue with a jQuery slide up/down animation

When I click a button, there is an animation that makes a div slide up and then down again. It functions the way I want it to, but the first time you click it, it doesn't work; you have to click twice for it to respond. Someone recommended using... ...

Positioning the comments box on Facebook platform allows users to

Need assistance, I recently integrated the Facebook comments box into my Arabic website, but I am facing an issue where the position of the box keeps moving to the left. Here is an example of my website: Could someone please suggest a solution to fix the ...

Achieve a centered content with a stretched background using Bootstrap 5

Having some trouble with aligning items in a div using align-items-stretch to stretch the background and align-items-center to vertically center the content. It seems that the alignment issue occurs when there's a very long title present. https://i.s ...

Oops! Error: EPERM - operation forbidden

When attempting to execute the yarn build command, I encountered this error message. An error occurred during the build process [Error: EPERM: operation not permitted, open 'C:\Program Files (x86)\cmder\podcastr\.next\routes-m ...

Issue with CancelToken in axios causing complications in a React project

I have been experimenting with using axios CancelToken in conjunction with react, but I am encountering an issue where the cancel token does not seem to be having any effect. To provide some context: There is an input field, and the getData() function is t ...

The Window.print() function may experience compatibility issues across different browsers

When attempting to utilize the Window.print() function, I encountered an issue where it works perfectly in Google Chrome but not in Mozilla Firefox. Attached are screenshots displaying the problem at hand. What could be causing this discrepancy? Furthermor ...

Customizing the COREui Admin Template to replicate the demo's design

Currently, I am delving into the world of web development and experimenting with integrating the COREui 4.0.1 Bootstrap admin template within an existing Symfony 5.3 project instead of utilizing standard Bootstrap 5 components and utilities. My goal is to ...

Update not being displayed on child component's UI

I am having an issue with two parent components, FirstParent and SecondParent, both of which share a common child component called Child. When I click on the Icon within FirstParent, the Redux state updates successfully and the UI displays the Text value ...

Guide on efficiently injecting data into a database using JavaScript and SQL from an array of objects

Let's simplify this process. I am creating a dynamic form for clients to submit data to a PostgreSQL database using React on the front end and NodeJs on the back end. Once the form is filled out, the inputs are stored in an array of objects like this ...

Having difficulty sending information to MongoDB from an external API

I'm currently facing an issue with fetching data from an external API and storing it in my MongoDB database. Despite using the GET and POST API with Hooks (UseState and UseEffect), my MongoDB object is being created without any data. I'm confuse ...

The overflowing issue with the Nextjs Tailwind Marquee Component is causing a display

I've recently developed a unique nextjs/tailwind component. This component displays an isometric marquee that scrolls horizontally. However, I'm facing an issue where the content overflows to the right and causes the page to become horizontally s ...

Troubleshooting Problems with Cascading Style Sheets

Struggling with a layout issue on my website. I need to display an image with text at the beginning of the site-wrap div under the name background-image, with the text inside that div. Adding line-height to the text div adjusts its height, but I want to m ...