I am trying to create a results text box containing text that the user will be expected to select and copy. I cannot use textarea because I need the text to support html markup. I have three nested divs with the following classes: entry-content
, content-area
, and selectme
. I would like the user to be able to select only the innermost div selectme
, and not have the selection area extend to the two parent divs. The following code seems to work fine on this JSfiddle, but when I apply the same css to my wordpress page I’m not getting the same effect. Thoughts?
.entry-content {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
.site-main {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
.selectme {
-moz-user-select: text;
-khtml-user-select: text;
-webkit-user-select: text;
-ms-user-select: text;
user-select: text;
}
Prevent the ugly selection with
display: inline-block
To prevent coloring outside the box when highlighting, use
display: inline-block
on your editable container. The selection will only apply to the divs text.Inconsistent behaviour of
user-select
The
user-select
property is not a w3c standard and is applied inconsistently.From the MDN (emphasis mine):
As an example of this unreliability, the
user-select
property on your website seems to work just fine for me in Chrome 39 on Windows ๐The
none
value does appear to have good support, but should not be relied upon: