18

With these css styles I prevent the highlighted text selection on a page. But this causes the input fields to be locked from user input on Safari.

* {
-webkit-touch-callout: none;
-webkit-user-select: none; // locks fields on Safari
-khtml-user-select: none; // locks fields on Safari
-moz-user-select: none;
-ms-user-select: none;
user-select: none;      
}

Is there a way on Safari to prevent user selection without interfering with input fields?

user823527
  • 3,644
  • 17
  • 66
  • 110

4 Answers4

28

Why not just apply the style to everything but the inputs?

css3 way: *:not(input){...}

Tom Pietrosanti
  • 4,184
  • 2
  • 24
  • 29
4

Nothing new :)

*:not(input, textarea){
    -webkit-touch-callout: none;
    -webkit-user-select: none; // locks fields on Safari
    -khtml-user-select: none; // locks fields on Safari
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
1

For every cases in css:

*:not(input), *:focus:not(input) {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  outline-style:none;/*IE*/
}
brydar
  • 151
  • 1
  • 4
0

I needed something a little more precise.

input[type=text] 
{
  -webkit-user-select: text;
}

input[type=password]
{
  -webkit-user-select: all;
}
  • whats the difference in terms of functionality? sorry i know i can try it, just really busy... – Craig Wayne Nov 11 '13 at 06:36
  • This will only select the specific input elements with the type attribute set to text or password. This is required for older browsers that don't support `not`. However, I would do this: `* { ... user-select: none; } input { ... user-select: text; }` – Timothy Zorn May 15 '15 at 19:39