CSS3 hover/tap doesn't work in mobile browsers

前端 未结 1 1133
無奈伤痛
無奈伤痛 2021-01-12 05:35

I created a box that fades into another div when hovered over. This was all done using CSS3. However, one problem I realized was that the hovers don\'t work in mobile browse

相关标签:
1条回答
  • 2021-01-12 06:05

    Hovers aren't possible on mobile devices as there is no persistent cursor - memory of the last touched point by default.

    The only way they can sense interaction is touch, which is akin to a click or selection, so :active in CSS or onclick in Javascript are your only options currently.

    Simplistically, in CSS you can define it:

    a.class:active {
      background-color: #AAA;
      ...
    }
    

    Or:

    .class:active {
      background-color: #AAA;
      ...
    }
    

    But you need to use the following workaround (or JS events: ontouchstart) to mimic the click:

    <body ontouchstart="">
    
    0 讨论(0)
提交回复
热议问题