Changing :hover to touch/click for mobile devices

后端 未结 9 1966
余生分开走
余生分开走 2020-11-28 19:43

I\'ve had a look around but can\'t quite find what i\'m looking for.

I currently have a css animation on my page which is triggered by :hover. I would like this to c

9条回答
  •  失恋的感觉
    2020-11-28 20:27

    I am a CSS noob but I have noticed that hover will work for touch screens so long as it's a "hoverable" element: image, link, button. You can do it all with CSS using the following trick.

    Change your div background to an actual image tag within the div or create a dummy link around the entire div, it will then register as a hover when you touch the image.

    Doing this will mean that you need the rest of your page to also be "hoverable" so when you touch outside of the image it recognizes that info-slide:hover has ended. My trick is to make all of my other content dummy links.

    It's not very elegant but it works.

提交回复
热议问题