4

I have a dropdown which uses CSS a#hoverlink:hover+div to make a div to appear, then you can click a link in the div.

On Android, when you click the hoverlink, it triggers :hover so this works fine.

I heard this isn't working in an iPad. How can I make it work? I'm thinking using :focus as an alternative to :hover would do the job. Will clicking trigger :focus in iPad safari?

I would just test it, but I don't have an iPad to try it with:

a#hoverlink+div { transition: all 2s; }
a#hoverlink:not(:focus)+div { visibility: hidden; opacity: 0; }
<a href="javascript:" id="hoverlink">the link</a><div> yes! focus worked, now wondering if click works<br/><a href="javascript:" onclick="alert('great, it worked!')">click here!</a></div>
700 Software
  • 85,281
  • 83
  • 234
  • 341

2 Answers2

1

You can try using :target. Below is a purely CSS example. You should be able to tweek it with Javascript to your needs.

Here is a reference for using :target https://css-tricks.com/on-target/

a#hoverlink+div { transition: all 2s; }
a#hoverlink:not(:target)+div { visibility: none; opacity: 0; }
<a href="#hoverlink" id="hoverlink">Show The Div</a>
<div>You should see this once the link is clicked</div>
IMI
  • 2,461
  • 1
  • 14
  • 20
  • Cool, did not know this was possible. – 700 Software Jun 09 '15 at 17:34
  • 1
    This method does work to create a mobile friendly css dropdown without the use of JS. I have tested it on several iOS and android devices. For a live use case you can visit http://paulrobertlloyd.com/ where he is currently using a similar :target technique for his mobile navigation. For anyone interested in the method behind his css mobile menu check out this page: http://www.creativebloq.com/netmag/build-smart-mobile-navigation-without-hacks-6126265 – IMI Jun 10 '15 at 12:24
0

Per the comments, it sounds like the :active idea doesn't work.

While IMI's :target technique would work, in my case it would conflict with JavaScript-driven use of the hash string for other purposes.

So my answer is just to use JavaScript onclick to add a class which will cause the dropdown to appear.

700 Software
  • 85,281
  • 83
  • 234
  • 341