Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Merge requests
  • !13049

Better handling of :hover on mobile by prefixing :hover selectors with .no-touch

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge grunt-no-touch into master Mar 13, 2014
  • Overview 0
  • Commits 4
  • Pipelines 0
  • Changes 16

Created by: cvrebert

So, this is one-half of a one possible solution to the problem of how mobile browsers treat :hover styles (see #12832 (closed), among several others).

What this does is add a prefix (.bs-no-touch) to every CSS selector that involves :hover and adds some JavaScript to detect whether the user-agent has touch functionality, and if not, then add .bs-no-touch to the <html> (or <body>?) element. (It should be possible to adapt the relevant portion of Modernizr into a tiny JS script for this.) Thus, :hover styles are only activated on non-touch devices, preventing the afore-referenced UX problems.

Issue: Requires JavaScript

  1. Desktop users with JS disabled would not get :hover styles.
  2. There are some platforms that allow for both touch and non-touch pointer inputs; such platforms would not get hover styles.

Possible mitigation for (1): Add a .bs-no-js <html>-level class and also autogenerate a .bs-no-js-prefixed version of every :hover selector.

Downsides of this mitigation:

  • Doubles the number of :hover-related selectors
  • Requires introducing another <html>-level class and more JS.
  • Shifts the degraded UX to touch devices that have JS disabled

Another possibility is to require the original HTML to have body.bs-no-touch and then instead have the JS remove the class if the device supports touch, but that requirement sounds rather intrusive.

Some Relevant Links

  • Original place where I found this idea: http://www.nczonline.net/blog/2012/07/05/ios-has-a-hover-problem/
  • http://leonardburton.co/2013/06/a-better-way-to-implement-hover-states-for-the-responsive-web/

CC: @mdo @twbs/team for discussion

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: grunt-no-touch