Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unselectable text in HTML on iOS

Tags:

html

css

ios

safari

If you visit this page on iOS, you will not be able to select any text.
This page doesn't contain any javascript or selection blocking code, actually if you open it on desktop browser everything will work.

I'm trying to implement EPUB3 reader on iOS and this page was generated with WYSIWYG EPUB3 editor.

So the problem is: How can I enable selection on this page without changing it visual layout?
And really important thing is: I'm hoping for solution which can be automated. So that I can preprocess this html files before opening in my reader.

Update: Selection starts working only when zoomed to about 400%.

like image 465
Alexander Avatar asked Jul 04 '13 18:07

Alexander


2 Answers

Here is a cross-browser list of styles for non-selectable text:

-webkit-touch-callout: none;
  -webkit-user-select: none;
   -khtml-user-select: none;
     -moz-user-select: moz-none;
      -ms-user-select: none;
       -o-user-select: none;
          user-select: none;

You can also set them to select text as well:

-webkit-touch-callout: default;
  -webkit-user-select: text;
   -khtml-user-select: text;
     -moz-user-select: text;
      -ms-user-select: text;
       -o-user-select: text;
          user-select: text;

The -webkit-touch-callout property allows you to dictate what does or doesn’t happen when a user taps and holds on a link on iOS. The default value is default and tap-holding on a link brings up the link bubble dialog; by using the value of none, that bubble never comes up.

The -khtml prefix predates the -webkit prefix and provides support for Safari 2.0-

The -moz prefix is defined twice with the value none and the value -moz-none on purpose. Using -moz-none rather than none prevents elements and sub-elements from being selectable. However some older browsers like Netscape won’t recognize moz-none so it’s still necessary to define none for them.

The -o prefix isn't supported but I have come across recommendations to include it for future proofing and it doesn't hurt unless minification is critical.

Non-prefixed property should be last in line.

like image 126
Matthew R. Avatar answered Oct 30 '22 04:10

Matthew R.


The computed height of #div8 is 0. Changing this to 100% fixes the issue for me.

like image 37
bridgepickup Avatar answered Oct 30 '22 02:10

bridgepickup