Currently, I have put this in the body tag to disable text selections:
body {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
However, my input
and textarea
boxes are now unselectable. How can I only make these input elements selectable and the rest unselectable?
To disable text selection highlighting in Internet Explorer/Edge browser using CSS just set -ms-user-select CSS property to none.
For a quick a glimpse of what you can do, just click anywhere in the middle of some text, hold down the [Alt] key, and make a small circle with your mouse. By using the [Alt] key while dragging your mouse, you can customize the shape and size of the selected block of text—it's up to you, not Word!
Use the user-select: none; CSS rule.
Don't apply these properties to the whole body. Move them to a class and apply that class to the elements you want to disable select:
.disable-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
You could also disable user select on all elements:
* {
-webkit-touch-callout:none;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
And than enable it on the elements you do want the user to be able to select:
input, textarea /*.contenteditable?*/ {
-webkit-touch-callout:default;
-webkit-user-select:text;
-moz-user-select:text;
-ms-user-select:text;
user-select:text;
}
Just wanted to summarize everything:
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="unselectable" unselectable="yes" onselectstart="return false;"/>
::selection,::moz-selection {color:currentColor;background:transparent}
you can disable all selection
.disable-all{-webkit-touch-callout: none; -webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}
now you can enable input and text-area enable
input, textarea{
-webkit-touch-callout:default;
-webkit-user-select:text;
-khtml-user-select: text;
-moz-user-select:text;
-ms-user-select:text;
user-select:text;}
Use a wild card selector *
for this purpose.
#div * { /* Narrowing, to specific elements, like input, textarea is PREFFERED */
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Now, every element inside a div with id div
will have no selection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With