May 30, 2012
CSS disable text selection
Question by Neil
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 reset unselectable
Answer by Someth Victory
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;
}
Answer by Starx
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.