view raw
JasonY JasonY - 6 months ago 38
Javascript Question

how to avoid highlighting all text over absolute positioned cousin div

I have a problem with text-highlighting,

There is a div cover absolute positioned on top of a paragraph. In the DOM structure they are cousins.

When highlighting the paragraph text underneath, once the cursor hovers over the cover, the entire paragraph gets highlighted automatically, how to stop this?

text selection before the cover:

mouse enters the cover all text gets selected

JS fiddle:

/*-webkit-user-select: none;*/

For some reason google slides is able to avoid this with svg,anyway to do it in html?


You can use

pointer-events: none;

on the #cover element

This removes normal pointer functionality from the element - highlight, hover, focus etc.

The CSS property pointer-events allows authors to control under what circumstances (if any) a particular graphic element can become the target of mouse events.