To simplify let’s talk of only three breakpoints: mobile, tablet and desktop. For the mobile version I am using a hamburger menu with enabled dropdown. For tablet und desktop I am using a classic menu without a dropdown.
I disabled it with the following code:
@media only screen and (min-width: 768px) {
.j-nav-has-children > ul {
visibility : hidden;
}
}
It works pretty well on desktop but on tablet I now have to double click the nav-item due to the hover effect that actually does nothing because the dropdown is deactivated. Is there a possibility to make the item one-click for the tablet view?
This is the default behaviour for ios so that you can get the hover effect on first touch and then a second touch activates the link. That’s why a lot of dropdown menus will still work on touch devices even though there is no hover as such.
However it can be confusing in some cases where there is no real hover effect to the link and some touch users may not think to touch again (or may not realise what is happening).
On navigation items I usually detect if ‘touch’ is available or not using JS and then have the JS add a class to the html element indicating if available or not.
e.g. add this class to the html element by default without using JS:
<html class="hasHover">
Then use js to detect if touch is supported and remove that class and add a different one which produces this result:
<html class="noHover">
With the above code in place you can re-write your menu rules so that any instances of :hover rules are prefixed with the ‘hasHover’ class.
e.g.
.hasHover ul#nav a:hover{background:red}
In that way touch devices do not get hover effects interfering with their actions. Of course that may mean rewriting many of the menu rules to accommodate this.
Here is a live example of that code so just view source to see appropriate html,css and JS.
It may be simpler when trying to fix something after the page has been coded to detect a click with js and act accordingly as mentioned in this article.