Quantcast
Channel: Media query to detect if device is touchscreen - Stack Overflow
Browsing latest articles
Browse All 15 View Live

Answer by superqwerty for Media query to detect if device is touchscreen

This works fine on Mozila-based and Webkit-based browsers:/* show only on mouse devices */@media (hover: hover), (-moz-touch-enabled: 0), (pointer:fine) { ...}/* show only on touch devices */@media...

View Article



Answer by Rohit Gupta for Media query to detect if device is touchscreen

I tried various options on various browsers and found that you need to use the hover and pointer both -@media (hover:none), (pointer:coarse){ .show_on_touch {display:inline}}The hover:none tells you...

View Article

Answer by iceman for Media query to detect if device is touchscreen

As of 5/5/2022:var isTouch = "maxTouchPoints" in window.navigator && window.navigator.maxTouchPoints > 1;var isTouchTwo = "ontouchstart" in window;var isTouchThree = window.matchMedia...

View Article

Answer by vIGGS for Media query to detect if device is touchscreen

I believe the better way to query a touch-screen with CSS (in 2022) is with (pointer:coarse), and definitely NOT with (hover:none), or a combination, as some suggest: (hover: none) and (pointer:...

View Article

Answer by aleksa_95 for Media query to detect if device is touchscreen

This will work. If it doesn't let me know@media (hover: none) and (pointer: coarse) { /* Touch screen device style goes here */}hover:none is true when hover is not supportedpointer:coarse is true when...

View Article


Answer by Robin Mehdee for Media query to detect if device is touchscreen

I was able to resolve this issue using this@media (hover:none), (hover:on-demand) { Your class or ID{attributes} }

View Article

Answer by Buzut for Media query to detect if device is touchscreen

There is actually a media query for that: @media (hover: none) { … }Apart from Firefox, it's fairly well supported. Safari and Chrome being the most common browsers on mobile devices, it might suffice...

View Article

Answer by Matoeil for Media query to detect if device is touchscreen

adding a class touchscreen to the body using JS or jQuery //allowing mobile only css var isMobile = ('ontouchstart' in document.documentElement && navigator.userAgent.match(/Mobi/));...

View Article


Answer by Sokołow for Media query to detect if device is touchscreen

In 2017, CSS media query from second answer still doesn't work on Firefox. I found a soluton for that: -moz-touch-enabledSo, here is cross-browser media query:@media (-moz-touch-enabled: 1),...

View Article


Answer by Patrick W. McMahon for Media query to detect if device is touchscreen

This solution will work until CSS4 is globally supported by all browsers. When that day comes just use CSS4. but until then, this works for current browsers. browser-util.jsexport const isMobile = {...

View Article

Answer by Simon E. for Media query to detect if device is touchscreen

The CSS solutions don't appear to be widely available as of mid-2013. Instead...Nicholas Zakas explains that Modernizr applies a no-touch CSS class when the browser doesn’t support touch. Or detect in...

View Article

Answer by Markus Hedlund for Media query to detect if device is touchscreen

There is actually a property for this in the CSS4 media query draft.The ‘pointer’ media feature is used to query about the presence and accuracy of a pointing device such as a mouse. If a device has...

View Article

Answer by Alex W for Media query to detect if device is touchscreen

Media types do not allow you to detect touch capabilities as part of the standard:http://www.w3.org/TR/css3-mediaqueries/So, there is no way to do it consistently via CSS or media queries, you will...

View Article


Answer by Starx for Media query to detect if device is touchscreen

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...

View Article

Media query to detect if device is touchscreen

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?

View Article

Browsing latest articles
Browse All 15 View Live




Latest Images