Make iOS Show CSS :hover Styles Without Any JS

Occasionally I’ll build an interaction that happens entirely in CSS via hover or focus on a non-standard element. Unfortunately, iOS doesn’t apply hover states when you tap on, say, a div. The solution is to get iOS to treat that element like a link by listening for clicks.

One way to do this without changing any other behavior on the page is to add an onclick to the desired element:

<div onclick="void(0)" class="fancy-hover">…</div>

Tapping will now trigger the :hover CSS styles for this element. Tapping away, doesn’t have the desired effect by default. In those cases, you can also add this:

<body onclick="void(0)">…</body>

This assumes you’re not using the onclick attribute because it’s 2017 and there are better ways of registering those click handlers. ;)

 
132
Kudos
 
132
Kudos

Now read this

Quick Tip to Clean Up Rails Logs

Every few months I use this command to empty each and every one of my test.log and development.log files in the src folder of my laptop: find ~/src \ -maxdepth 6 \ -type f \ -mindepth 1 \ \( -name "test.log" -or -name "development.log" \... Continue →