Recently, I encountered a rather embarrassing CSS oversight. I was developing a website with a narrow sidebar containing icons. Lacking space for descriptive text, the design called for accessible, yet initially hidden, tooltips triggered by a prolonged hover. The tooltip would appear after a three-second hover.
My initial approach involved JavaScript state management:
- A state variable to track tooltip visibility (visible/hidden). This state would update a class on the relevant HTML element.
- Event listeners (
mouseenter
,mouseleave
) to manage the state transitions. - A three-second delay before setting the state to
visible
onmouseenter
. - The tooltip would remain hidden (
mouseleave
).
This was a React project, so using JavaScript state felt natural. However, in retrospect, it proved unnecessarily complex. The mouseenter
and mouseleave
events felt slightly unreliable, and the entire functionality could have been implemented more concisely and efficiently with CSS alone.
The embarrassing realization: I unnecessarily leveraged a JavaScript library when a CSS solution was readily available.
I retained the React UI but removed the JavaScript state management. The solution involved a simple CSS transition-delay
property:
.thing { transition: 0.2s; } .thing:hover { transition-delay: 3s; /* delay hover animation only ON, not OFF */ }
This elegant one-liner perfectly achieves the desired long-hover effect.
This approach, however, doesn't fully address touch screen accessibility. While screen readers handle the accessible text and desktop users benefit from the tooltips, touch-only users might miss the icon labels. My project targeted large screens, assuming cursor availability, but touch accessibility remains a concern. If the element is a link, the :hover
might activate on the initial tap. If the link leads to a page with a clear title, that might provide sufficient context. Otherwise, JavaScript event handling for touch events remains a viable option.
The above is the detailed content of Long Hover. For more information, please follow other related articles on the PHP Chinese website!

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more.

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)
