Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent selection from Shift+Click [duplicate]

Possible Duplicate:
css rule to disable text selection highlighting
Prevent text selection after double click

Even though my events are properly prenting default actions, clicking in text and then Shift-clicking in other text is causing a selection. This is undesirable behaviour in this case, since I'm using Shift-click to multi-select these elements.

Is there something I need to do to specifically disable selection here?

EDIT: Found solution to my own problem here. Sorry for wasting people's time.

like image 218
Niet the Dark Absol Avatar asked Oct 10 '12 16:10

Niet the Dark Absol


People also ask

How do you stop a selection in CSS?

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 do you stop highlighting text when clicking in CSS?

To disable text selection highlighting in Google Chrome browser using CSS just set -user-select CSS property to none. And no prefix is required for Google Chrome and Opera Browsers.

How do you make it so you can't highlight text in CSS?

Use the user-select: none; CSS rule.


1 Answers

Add this CSS to the section where you want to prevent text-selection:

-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;

Earlier versions of IE require you to add the attribute onselectstart, something like this:

<div onselectstart="return false">
like image 150
Porco Avatar answered Sep 17 '22 12:09

Porco