I'm trying to add a CSS rule that makes the default behaviour to not allow selection of text or elements on a page. I then add a rule for specific nodes (such as paragraphs or header text) to allow text selection on them.
Unfortunately this does not work as expected and it seems impossible to override this setting on a child node.
Check this jsfiddle to see what I mean:
http://jsfiddle.net/cH8WD/
Any idea how I can get this to work properly?
Thanks
Edit:
To better illustrate the problem:
http://jsfiddle.net/cH8WD/5/
You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.
To make a text unselectable in CSS, we use the user-select property. If you want a text not to be selected by the user, simply apply user-select: none; property on that particular element. It will prevent all kinds of selection events on the element.
try "text" instead of "normal" like:
* {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: -moz-none;
-o-user-select: none;
user-select: none;
}
p, h1, h2, h3, h4, h5 {
-webkit-user-select: text;
-khtml-user-select: text;
-moz-user-select: text;
-o-user-select: text;
user-select: text;
}
edit: for FireFox, i changed the line "-moz-user-select: none;" to "-moz-user-select: -moz-none;"
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