The CSS hover animation functions smoothly in CodeSandbox using React, but encounters issues when integrated into a Next.js project

Challenge

Here, in my codesandbox project, I created a hover animation for a div element. When I implemented the code on a li element in my next.js project, the hover effect is triggered not on hover, but on click. Additionally, the element remains in the hovering state until clicked again. Strange, right?

Check out this video I recorded for reference --> https://www.youtube.com/watch?v=IV7PIvmpzX8

Can you identify what might be causing this issue?

Here is the relevant code snippet:

import Link from "next/link";
import styled from "styled-components";

console.clear();

const StyledUl = styled.ul`
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
  padding: 0px 50px;
`;
const StyledLi = styled.li`
  display: grid;
  place-items: center;

  height: 80px;
  position: relative;
  box-shadow: rgba(0, 0, 0, 0.12) 0px 1px 3px, rgba(0, 0, 0, 0.24) 0px 1px 2px;
  border-radius: 20px;
  transition: all 0.1s ease-in-out;
  &:hover {
    transform: scale(1.1);
  }
  &:hover::after {
    opacity: 1;
  }
  &::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.1s ease-in-out;
  }
`;
const StyledP = styled.p`
  font-size: var(--fontsize_pageText);
`;

export default function Main() {
  return (
    <StyledUl>
      <StyledLi>
        <StyledP>something</StyledP>
      </StyledLi>
      <StyledLi>
        <StyledP>something</StyledP>
      </StyledLi>
      <StyledLi>
        <StyledP>something</StyledP>
      </StyledLi>
      <StyledLi>
        <StyledP>something</StyledP>
      </StyledLi>
    </StyledUl>
  );
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

Answer №1

The behavior is typical when browsing in tablet or mobile mode as most browsers switch from a standard cursor to an emulated touch cursor, which then triggers touch events instead of regular desktop browser events.

If you're using Chrome, you can modify this behavior by utilizing their tools as outlined in their documentation.

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

How to Ensure the Final Column in an Angular Bootstrap Row Occupies the Remaining Available Space

Within my Angular5 application, there is a container component used to display a row with multiple components arranged in n columns, as shown below: <div class="row mx-5 my-5 h-75 w-80"> <div class="col-md-4 col-lg-4 m-0 p-0" *ngIf="advanc ...

Floating color problem

Do you know why the social icons turn black when hovered over? Could it be related to the navbar buttons? Is there a way to change the hover color to blue or red only? Link to code snippet <body> <nav class="navbar navbar-default navbar-fixed-t ...

How to move content without affecting the background of the `<body>` using scrolling

Can I achieve a glass morphism effect on my page without moving the background of the body? I only want to move the .container. Is this feasible? I attempted using background-attachment: fixed, but it did not work for me. Here is the code snippet I have be ...

I'm experiencing an issue with my website where it appears broken when I build it, but functions properly when I use npm run dev in Next

For my project, I have utilized NextJs, Tailwind, React, and Typescript. It is all set and ready to be hosted. After using "output: export" in next.config.js and running npm run build, the process was successful. However, when viewing my website locally, I ...

Conceal div elements and retain their status when the page is reloaded or switched

I currently have 3 div elements displayed on a webpage: header-div fixed_menu_div page_cont Each of these divs are styled with the following CSS properties: #header-div { top:0; left:0; display:inline; float:left; } #page_cont { mar ...

Using Firebase Admin or the regular Firebase with Next.js

Currently, I am working on a project using Next.js and integrating Firebase. I have been successfully fetching data in my components using the Firebase package designed for frontend use. However, I recently attempted to utilize Firebase within getServerS ...

Leveraging Next.js 13: Implementing async server-side rendering for components nested within client-side components

How can I asynchronously set a Server Side Component within a Client Side Component? // Parent Client Side Component "use client" export function ParentCSC(){ return <ChildSSC/> // hoping to apply async or suspense here } // Child Server ...

The size of Bootstrap 3 columns adjusts dynamically based on the width of the window as the page is being

I am facing an issue with the layout of my bootstrap site when resizing the 3 horizontal columns based on the window size upon page load. Currently, I have a script that adjusts the height of each column to match the tallest one so they appear uniform whe ...

Vertical stability bar

I need help creating a vertically fixed navigation bar for my website. Currently, I am using a method that has been discussed in various posts: HTML: <html> <head> src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">< ...

What is the correct way to horizontally center a Material icon within a div?

How do I correctly center a Material Design icon within a div to fix the gap issue? I have tried using text-align on the items div, but it hasn't worked. (Refer to screenshots for clarification) https://i.sstatic.net/eHuiR.png https://i.sstatic.net/nL ...

What is the reason that em takes precedence over p for font-family?

Take a look at this CSS snippet: * { font-family: Gill Sans, Verdana, Arial, Helvetica, Sans-Serif} p { font-family: Courier; } Now let's consider this HTML markup: <p>Hi there. So <em>very</em> pleased to make your acquaintance. ...

The drop-down menu selection is non-functional on mobile and iPad devices when using Bootstrap

<div class="panel panel-default"> <select> <option value="B3">B3</option> <option value="B4">B4</option> <option value="B5">B5</option> & ...

Tips for correctly loading all elements on an HTML page before making CSS modifications

This question has been asked several times in the past. I am asking because when I used the on ready callback in jQuery, it did not change the placeholder text of my element "search_input". $( document ).ready(function() { $("#search_input").attr(' ...

Adjusting Column Order in Bootstrap 4 for Mobile Screens

I have a unique challenge regarding changing the order of columns in Bootstrap for mobile devices. While I have come across many Stack Overflow questions on this topic, none seem to address changing the order of columns that are on different rows. <d ...

Setting expiration dates for cached images

I am interested in optimizing the loading speed of my webpage by setting an expiration date for images. However, I am unsure about where to specify this. The images on my website are loaded via CSS from Cloudfront using an S3 bucket in AWS. Can you provid ...

NextJS, Clerk - User will not be affected by organizational changes

I integrated Clerk for user authentication in my app's backend and assigned an organization to a user with the admin role using Clerk's dashboard. However, when I try to access user information within the Clerk middleware, the orgId is showing as ...

Align Text Center inside a Magical H1 Heading Tag

I'm having a bit of trouble with something that should be simple. I want to center the text inside my h1 tag on a wizard, and I've added this CSS to my stylesheet.css: .h1textalign { text-align:center; } Here's how I'm trying to apply ...

Expanding Beyond Boundaries: Utilizing CSS to Overflow From a Div and Fill the Entire Screen

I have a main DIV that acts as part of my responsive layout grid. It grows to the maximum width I've set, which is 1280px, and then adds margins for larger devices. Below you'll find my CSS along with a snippet of Less code. .container { mar ...

Develop a responsive design for a row of icons that automatically flows to a second line when the screen size is

Currently, I am utilizing Bootstrap 4 and attempting to design a row of 12 icons that are responsive. <div class="app-container"> <div class="row"> <div class="col-md-1"> <a class="" href="https://www.xxx.org.au"> < ...

Creating a Bootstrap 4 DIV element with horizontal scrolling functionality

I've been struggling to implement a horizontal scroll for a DIV on my site, but none of the common solutions like overflow-x or white-space:nowrap are working for me. This is the section of my website where I need a horizontal scroll bar If you want ...