Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impossible to override user-select on child nodes?

Tags:

css

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/

like image 737
Naatan Avatar asked Oct 12 '11 14:10

Naatan


People also ask

How do you prevent the user from selecting the test rendered inside the following element?

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.

How to make a text unselectable in CSS?

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.


1 Answers

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;"

like image 126
Emir Akaydın Avatar answered Nov 06 '22 16:11

Emir Akaydın