Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:hover on ios mobile devices turns into double-touch instead of hover

Tags:

css

ios

hover

touch

First off, this is not a clone of: iPad/iPhone hover problem causes the user to double click a link because I want an answer that is purely CSS. All of the answers in this link require js or jQuery and the one CSS answer involves background images. I'm trying to change the opacity and that's it.

CSS wants to gear itself towards the mobile revolution yet every solution I see for a simple 'touchDown'(aka touch-hover) creating a hover effect requires javascript or jQuery.

Here's some simple code to illustrate what I mean:

.btn {
  border-radius: 5px;
  display: block;
  opacity: 1; <--from
  background: red;
  text-align: center;
  line-height: 40px;
  font-weight: bold;
  &:hover {
    opacity:.7; <--to
    transition: opacity .2s ease-out; <--fun fade animation :)
    -moz-transition: opacity .2s ease-out;
    -webkit-transition: opacity .2s ease-out;
    -o-transition: opacity .2s ease-out;
  }
}

Tested in Chrome & Safari

like image 204
Ian Steffy Avatar asked Sep 03 '15 09:09

Ian Steffy


People also ask

Does CSS hover work on mobile devices?

Hover effects inform users what they can interact with by providing visual feedback on buttons. But there's a problem — hover effects are for desktop apps, not mobile apps. There are no mouse devices on mobile, so users don't have the luxury of using hover effects.

Does hover work on iOS?

Hover works by hovering the mouse on an object, without clicking at it. This can't be done on neither Android nor iOS. If you want to test your code, test it on a computer.

How do you use mouseover on iPhone?

The usual method cited for viewing the mouse-over text of an image on an iOS device is to press and hold on the image. This works for most images with mouse-over texts. For example, pressing down on the image in.


Video Answer


1 Answers

iOS will not trigger a link click event on the first tap if the :hover state either:

  • Has a CSS transition animation
  • Reveals child content (such as a submenu, tooltip or ::before/::after element)

In both cases the first tap will trigger the :hover state and a second tap will trigger the link (or click event).

If you remove the animation or the child elements you should get it to trigger within a single tap.

This great article from CSS Tricks digs a bit deeper into the issue:
The Annoying Mobile Double-Tap Link Issue

like image 166
Simon East Avatar answered Oct 13 '22 23:10

Simon East