The hover effect is being applied exclusively to the final React component

When using next.js and tailwindCSS for styling, I created a custom component that includes tags. The issue arises when multiple instances of this component are placed on the page, as only the last one is getting the desired hover effect.

"index.js"

import TableRow from "@/components/TableRow";

export default function Home() {
  return (
    <>
      <TableRow imageurl="https://i.ibb.co/Gp1kWY0/Keeps.png" />
      <TableRow imageurl="https://i.ibb.co/NsK00Vx/Amazon-Pharmacy.png" />
      <TableRow brand="HappyHead" imageurl="https://i.ibb.co/hBffkXR/Happy-Head.png" />
      <TableRow imageurl="https://i.ibb.co/9r9xNZH/hims.png" />
      <div className="pb-24"></div>
    </>
  )
}

"_app.js"

import 'tailwindcss/tailwind.css'
import '@/styles/fonts.css'

export default function App({ Component, pageProps }) {
  return <Component {...pageProps} />
}

"TableRow.js"

import React from 'react';

const TableRow = (props) => {
  
  return (
    <div className="w-[1400px] h-[40px] pt-28 left-56 relative ">
      <div className="w-10/12 pb-4 items-center flex flex-row justify-between">
        <img src={props.imageurl} className="w-[130px] object-contain" alt="keeps" />
        <a className="relative text-center right-16 text-4xl text-blue-500 productpricelink" href={props.foamlink}>${props.foamPrice}</a>
        <a className="relative text-center right-10 text-4xl text-blue-500 productpricelink" href={props.solutionlink}>${props.solutionPrice}</a>
        <a className="relative text-center right-2 text-4xl text-blue-500 productpricelink" href={props.finlink}>${props.finPrice}</a>
      </div>
      <div className="h-[4px] bg-[#D9D9D9]"></div>
    </div>
  
  )
};

export default TableRow;

"fonts.css"

.productpricelink {
    transition: all 0.3s;
    font-family: 'Montserrat', sans-serif;
  }
    
  .productpricelink:hover {
  color: #ffffff;
  background-color: #2c3e50;
  text-decoration: none;
  font-weight: bold;
  padding: 5px;
  border-radius: 14px;
}
  

I have attempted to troubleshoot by modifying the text color within .productpricelink to test if only specific components were affected by the class, but all components changed uniformly. Copying and pasting the last component also did not resolve the issue, as only the final TableRow retains the hover style.

Answer №1

After troubleshooting, it was discovered that the hover state on my <a> tags wasn't registering due to overlapping elements. I resolved this issue by including a z-index property in my .productpricelink class, resulting in the desired behavior for the state change.

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

Styles are not applied by Tailwind to components in the pages folder

NextJS project was already created with tailwind support, so I didn't have to set it up myself. However, when I add className to an HTML element in a component within the pages/ folder, it simply doesn't work, even though the Elements panel in D ...

Having trouble positioning a specific element at the top right of the header navbar in Laravel Bootstrap 5

Is there a way to create a top navbar with the project name and menu on the left, and user management on the right? Currently, both options are aligned to the left. Here is an example of what I have: top navbar This navbar is placed in the header, and her ...

an li element is accompanied by a visible box

In my possession is a container: #box1 { height:100px; width:208px; } along with a series <li id="first"><strong>FIRST</strong> </li> <li id="second"><strong>SECOND</strong&g ...

Is it better to specify one root element or render the entire layout in ReactDOM.render()?

Currently in the process of learning React.js and I have a question. Is it more beneficial to keep my ReactDOM.render() as it is currently set up: ReactDOM.render( <div className="container"> <div className="row"> <div className ...

Encountering an issue with npm installation following a recent node version upgrade

Having trouble installing Sass on Node version v16.14.0. I keep receiving this error message: https://i.stack.imgur.com/6KNcF.png ...

Create a dynamic HTML table in React by leveraging arrays

I am working with two arrays: headings=['title1','title2'] data=[['A','B'],['C','D']] How can I efficiently convert this data into an HTML table that is scalable? title1 title2 A B ...

Adjusting Anchor Links to Account for a Fixed Header

There have been a few posts discussing similar issues (like offsetting an html anchor to adjust for fixed header), but none of the solutions seem to work for my specific situation. I am currently using jQuery to generate a Table of Contents, following the ...

What is the best way to connect a CSS file with multiple pages located within a specific folder in HTML/CSS?

In my CS 205 class project, I am tasked with creating a website. To accomplish this, I used Notepad++ for the HTML files and Notepad for the CSS files. The site consists of an index.html page along with other content pages, each designed separately in Note ...

Employ CSS Grid to properly position the crimson section within the confines of the scarlet border on Level 77 of Grid Attack

I spent hours struggling with level 77 of Coding Fantasy: Grid Attack. No matter what I tried, nothing seemed to work. There are no solutions provided in the game, and there's no way to skip the level. Can anyone help me with the solution please? ...

Avatar image is not showing up on the browser due to the use of Material UI

As a newcomer, I am eager to start working on a project. After browsing through various questions, none seem to address my specific issue. I am struggling to figure out what is missing in my current setup. I have successfully imported an image in Compone ...

Angular JS integration for optimal Bootstrap grid alignment

Recently, I have been exploring the Bootstrap framework and experimenting with grid alignment. When working with 4 columns, W3 schools recommends using the following row setup: <div class="row"> <div class="col-lg-3"> </div> ...

Enhancing search results with data retrieved from a jSON response

At the moment, I am using a logic to generate a list of titles. Now, I would like to include data from the response along with the code for each title in the list. const title = responseData.map(item => { return { label: item.title, val ...

Display a series of numbers in a stylish Bootstrap button with uniform dimensions

I am trying to find a way to show the number of days in a specific month within a bootstrap button. However, the code I have been using does not evenly distribute the buttons in terms of height and width. I would like the display to look similar to the sc ...

What could be causing the error message to appear stating that each list item must have a unique key when utilizing react-bootstrap in Nextjs?

My file currently contains keys for each child component, but it is still raising an error internally. I am unsure if I can resolve these issues on my own. export default function SecondaryNav(props:NavItems) { const router = us ...

Using a component as a route in Next.js: A step-by-step guide

I am interested in creating a feature that resembles the popups on Facebook, where dynamic content such as images and text are displayed. When clicking on an item, I would like a popup to appear with a URL structure similar to /post/343542. Currently, I h ...

The React Material UI Select component shows an issue where the selected value does not update after choosing an item from the dropdown menu

This snippet represents a portion of the code I have been working on. My approach involves fetching drug data and categorizing them based on their class. I then proceed to map these categories, checking if a drug belongs to a certain category. If it does, ...

Creating a fixed-size set in React with randomly ordered elements

I am currently working on a project where I need to retrieve a random array from a .json file using React. My goal is to create 16 cards, each displaying a number that appears twice. To ensure uniqueness, I am utilizing a Set, but I am facing an issue with ...

Contrasting methods of adding a value to an array state in React

Can you advise me on the most effective method for inserting a value into an array, as well as explain the distinctions between these two code examples? setOtoValue((current) => [ ...current, Buffer.from(arraybuf, 'binary').toString(' ...

Is it necessary for React components to be organized in a hierarchy?

In all my years, I've been told that React components should follow a tree hierarchy so that parent components can manage state and pass it down to their children. But is this truly necessary? The guiding principle of React states that "React has bee ...

Media Queries seem to be unresponsive on Tablet and Desktop devices

I've been trying to resolve this issue for quite some time now, but I'm still unable to find a solution. My goal is to center the Wufoo Forms visually on different screen sizes using media queries, however, despite rewriting them multiple times a ...