Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop highlighting of a div element when double-clicking

I have this div element with a background image and I want to stop highlighting on the div element when double-clicking it. Is there a CSS property for this?

like image 963
dave Avatar asked Aug 10 '11 21:08

dave


People also ask

Do not select text on double click CSS?

If you are trying to completely prevent selecting text by any method as well as on a double click only, you can use the user-select: none css attribute.

How do I turn off highlighting in HTML?

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 I turn off highlight text?

Remove highlighting from part or all of a document Select the text that you want to remove highlighting from, or press Ctrl+A to select all of the text in the document. Go to Home and select the arrow next to Text Highlight Color. Select No Color.


5 Answers

The CSS below stops users from being able to select text. Live example: http://jsfiddle.net/hGTwu/20/

/* If you want to implement it in very old browser-versions */
-webkit-user-select: none; /* Chrome/Safari */ 
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */

/* The rule below is not implemented in browsers yet */
-o-user-select: none;

/* The rule below is implemented in most browsers by now */
user-select: none;

To target IE9 downwards and Opera the HTML attribute unselectable must be used instead:

<div unselectable="on">Test Text</div>
like image 175
tw16 Avatar answered Nov 14 '22 08:11

tw16


This works for me

html
{
  -webkit-tap-highlight-color:transparent;
}
like image 21
Hans Avatar answered Nov 14 '22 07:11

Hans


I was trying to find a solution to stopping div highlighting in Chrome, and turned to this post. But, unfortunately, none of the answers solved my problem.

After a lot of online research, I found that the fix is something very simple. There is no need for any complex CSS. Just add the following CSS to your web page and you are all set. This works in laptops as well as mobile screens.

div { outline-style:none;}

NOTE: This worked in Chrome Version 44.0.2403.155 m. Also, it is supported in all major browsers of today as explained at this url: https://developer.mozilla.org/en-US/docs/Web/CSS/outline-style

like image 43
Sunil Avatar answered Nov 14 '22 06:11

Sunil


I'm no CSS expert, but I think you can use tw16's answer as long as you expand the number of elements affected. For instance, this prevents highlighting everywhere on my page without affecting any other kind of interactivity:

*, *:before, *:after {
    -webkit-user-select: none; /* Chrome/Safari */        
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+ */
}

That first line is courtesy of Paul Irish (via http://adamschwartz.co/magic-of-css/chapters/1-the-box/).

like image 43
SterlingVix Avatar answered Nov 14 '22 07:11

SterlingVix


Target all div elements:

div::-moz-selection { background:transparent; }
div::selection { background:transparent; }

Target all elements:

::-moz-selection { background:transparent; }
::selection { background:transparent; }
like image 40
jasonleonhard Avatar answered Nov 14 '22 08:11

jasonleonhard