Hover effects can cause strange behavior when viewed on mobile devices

I am encountering a strange issue while developing a web application for mobile devices. Everything was going smoothly until I encountered a problematic behavior. The app consists of a Welcome screen with a "Get Started" button in the middle, which leads to a page displaying products in a 2x2 grid format. Each product has a hover effect that blurs the image and displays its name and price. However, after clicking "Get Started," one of the items in the grid is automatically selected (hovered) even though it shouldn't be pre-selected.

Step one: Main welcome screen when the user clicks Get Started button:

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

Step two: User has clicked Get Started and goes to the products list with one item marked as selected/clicked due to the hover effect

https://i.sstatic.net/5RwYW.png

Here's the HTML/CSS code for the hover effect on the product names and prices:

<ul className="list-products">
    {productsStore.menuProducts.filter(p => p.sectionId == productsStore.activeSectionId).map((product, index) => {
        return (
            <li key={index} onClick={() => handleOnProductClick(product.id)}>
                <button>
                    <small style={{ backgroundImage: "url(" + getDefaultImage(product.image) + ")" }}></small>
                    <strong id={product.id}>
                        <span>
                            {product.name}
                            <em>{product.price.toFixed(2)}</em>
                        </span>
                    </strong>
                </button>
            </li>
        )
    })}
</ul>

.list-products { display: -moz-flex; display: -ms-flex; display: -o-flex; display: flex; flex-wrap: wrap; }
.list-products li { width: 50%; position: relative; padding-bottom: 50%; border-bottom: 1px solid #252525; }
.list-products li:nth-child(odd) { border-right: 1px solid #252525; }
.list-products li button { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #fff; border: 0; border-radius: 0; }
.list-products li button strong { position: absolute; top: 0; left: 0; width: 100%; height: 100%; font-weight: 400; background: rgba(0,0,0,.3); opacity: 0; }
.list-products li button:hover strong { opacity: 1; }
.list-products li button strong { display: -moz-flex; display: -ms-flex; display: -o-flex; display: flex; align-items: flex-end; justify-content: center; padding: 10px; }
.list-products li button span { display: inline-block; font-size: 18px; text-align: left; width: 100% }
.list-products li button span em { font-style: normal; display: block; }
.list-products li button small { background-size: cover; background-position: center; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.list-products li button:hover small { filter: blur(2px); -webkit-filter: blur(2px); }

I forgot to mention that I'm using React. This unusual behavior only occurs on mobile devices, specifically tested on an iPhone with Safari browser. It does not replicate on PC even with mobile view enabled.

My theory is that the hover effect triggers when a user taps on the screen, causing the item to stay hovered until another interaction. Since we clicked "Get Started" near the button location, the browser assumes it is still being hovered. What could be the solution to this issue?

Answer №1

It seems like your guess is spot on. Hover effects tend to behave oddly on mobile devices. Upon tapping the element, it often quickly triggers the hover effect before redirecting users to the next link. In some cases, phones might store this triggered hover effect and continue displaying it consistently. For a smoother user experience on mobile, it's advisable to stick to on-click effects instead of hover effects. Hopefully, in the future, our phones will provide better support for this.

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

Designing a drop-down menu that appears visually above its parent

As I design a menu positioned at the bottom using position:absolute; bottom:0, I want the submenu items to align perfectly above their parent. Each li should appear above the ul itself. The trick to achieving this is by applying a negative margin. However ...

A minimalist web page appearing as blank in Internet Explorer

After testing my simple web page in various browsers, I discovered that it only showed a blank white page in Internet Explorer. I combed through my CSS code and identified background = rgba(some stuff) as the unsupported line by IE. However, this particula ...

Attempting to retrieve backend data through an API to be displayed on the frontend

After successfully sending form data from my React front end to the server using fetch, I am struggling to make this data accessible from the front end again. Despite being able to access and utilize the data within my API function on the server side, I&ap ...

Locating the elusive comma - unraveling the mystery of Javascript Arrays nested within Objects

I've managed to put together something that functions as intended, but I'm facing an issue where I get a comma between entries when there are multiple ones. Here's the code snippet: chrome.runtime.onMessage.addListener(function (message, s ...

What are the steps to incorporating the League Gothic font into my website design?

Is there a way to incorporate League Gothic font into my website design? Visit the League Gothic GitHub repository Appreciate any guidance on this matter, ...

Struggling to create a unique grid layout with bootstrap framework

After working with Bootstrap for about a month, my HTML code may be a bit messy. The current task requires me to create a custom slick carousel in order to achieve a user interface similar to the image linked below: https://i.sstatic.net/vBIFP.png With my ...

Whenever I try to refresh the browser, my React app displays a message indicating that the page is not supported

Recently, I started my journey in React app development and successfully built a practice app which I deployed through Netlify. However, everything seems to be working fine until I encounter an issue when refreshing the window - it shows an error message ...

Tips for positioning the title of a card in Bootstrap-Vue

I'm currently working with the <b-card> component from bootstrap-vue and encountering an issue where I am unable to center align the title property. Does anyone have a solution for this problem? Below you can find the structure of my card, which ...

Office Outlook Client experiencing incorrect div width

I'm having trouble sending an email with HTML content because it's not displaying correctly in Microsoft Office Outlook when it comes to width. Any suggestions on how to fix this issue? <div style="width: 650px; border: 1px solid blue">hel ...

How to transfer a java list to an html template

I have extracted some information from an HTML file that relies on input from a Map structure as demonstrated below Template t = TemplateLoader.load("Printing/account.html"); Map<String, Object> map = new HashMap<String, Object>(); map.put("a ...

Having an issue with my webRTC video call on nodejs

Currently, I am utilizing webRTC for a video call application. It is functioning perfectly when tested locally. However, once I host my react app and node backend on an IP address, the chat works without any issue but encounters an error in the specified f ...

Create circular Styled components in React JS

Currently, I am attempting to create a component within a wrapped styled component. The Styled component has a circular shape, and I am seeking assistance in styling it accordingly. Can anyone provide guidance on how to apply the styles needed to achieve a ...

css hover function not operational with back to top button

I have implemented a back to top button using the following resource: Although the button is functioning as expected, I am encountering an issue with the hover effect. In Chrome inspector, manually forcing hover on .cd-top does not apply the CSS style as ...

Tips for preserving state with history.replaceState

Recently, I experimented with the window.history.replaceState function in order to display a specific URL in the browser. window.history.replaceState("", "", "newurl.php"); Although the method successfully changed the URL, I found myself wondering about t ...

Button elements are not responsive to Bootstrap margin classes

I am facing an issue in my code where adding the class m-0 to a button is not working to reduce the margin around it to 0. However, when I include .close {margin:0;} in my SCSS file, it successfully reduces the margin to 0. Even though I was advised agains ...

Steps for connecting a text to the Polyline feature in the React Google Maps API

I am attempting to display the distance attribute on top of the PolyLine with a 45% offset (almost next to the arrow) in this code snippet. Despite my efforts, I have not been able to achieve this successfully. <GoogleMap id="react-google-m ...

The user data stored in the useContext() in React.js may not be complete until the page has finished loading and all

I worked on a project using React. In the main App.js file (the entry point of the application), I fetched the current user data from an API in this manner. function App() { const [user, setUser] = useState(null); const [isLoading, setIsLoadin ...

"Enhance an image's focus by centering and zooming in on it with the click

I created a custom jQuery function to implement image zoom functionality. The code starts by hiding all images and ends by zooming the current image. In between, there is logic written to display the image in the center of the screen. However, the code i ...

Executing a function for every element within a loop in Angular 11 - the Angular way

I'm currently developing a project using Angular in which users have the ability to upload multiple questions simultaneously. After adding the questions, they are displayed in a separate modal where users can include diagrams or figures for each quest ...

Unable to access the function this.context.getStore in ReactJS Stores due to an error

I currently have the following code: import React from 'react'; import FilterButton from './FilterButton'; import FilterJobsScreen from '../../actions/jobs-screen/FilterJobsScreen'; import JobStore from '../../stores/Jo ...