Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Show elements on touchscreen devices only

I've got layout in which 80% of buttons are icons with tooltip describing the function appearing on :hover

Is it possible using CSS and Media Queries only to show additional class (for example .button-info) if website is viewed on touchscreen device. Other than guessing by the resolution and orientation what sort of device user might be using?

like image 954
Pejs Avatar asked Mar 17 '26 11:03

Pejs


2 Answers

What you are requesting is being developped by the W3C for CSS4: http://dev.w3.org/csswg/mediaqueries-4/#pointer

You'd use :

@media (pointer: coarse) and (hover: none) {
    /* your touchscreen specific rules */
}

But it is NOT available right now, so you'll have to use a workaround, with device widths and orientations.

NB: That is if you want to use a CSS only solution.

like image 92
Antoine Combes Avatar answered Mar 20 '26 00:03

Antoine Combes


Similar to this question (Media query to detect if device is touchscreen)

This guy has some good points that you should consider.

http://www.stucox.com/blog/you-cant-detect-a-touchscreen/

He talks about the various ways of achieving what your trying to do, then explains what the pitfalls are. Ultimately concluding that if your trying to detect if it's a touch screen then your probably going about it the wrong way anyway.

Consider treating all users as touch screen users because not everyone looks around the screen with the mouse cursor.

like image 38
hman Avatar answered Mar 20 '26 00:03

hman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!