What is the safest way, using media queries, to make something happen when not on a touchscreen device? If there is no way, do you suggest using a JavaScript solution such as !window.Touch or Modernizr?
What is the safest way, using media queries, to make something happen when not
Share
Nowadays, CSS Media queries can be used to define style for devices with specific interactive features and it’s widely supported as well.
hover for example can be used to test whether the user’s primary input mechanism can hover over elements (which would not be true in touch-enabled devices without emulating)
Other interactive tests are: pointer, any-pointer, hover, and any-hover
Previous answer
I would suggest using modernizr and using its media query features.
However, using CSS, there are pseudo class like, for example in Firefox. You can use :-moz-system-metric(touch-enabled). But these features are not available for every browser.
For Apple devices, you can simply use:
Especially for iPad:
But, these do not work on Android.
Styling Touch Elements
Modernizer adds classes to the HTML tag for this exact purpose. In this case,
touchandno-touchso you can style your touch related aspects by prefixing your selectors with .touch. e.g..touch .your-container. Credits: Ben Swinburne