Search code examples
javascripthtmlcssmouse-cursor

Display different cursor when over text (NOT element)


When a default cursor hovers over a text, it changes to a caret-shaped cursor. However, it only does when over text: everywhere else inside the element,it will not display that specific cursor.

As an example, here's how I want it to work: 1

Is it possible to get that to work?


Solution

  • It seems that there's currently no way to apply separate styles (here, cursors) to only text nodes using CSS. However a similar effect can be achieved using <span>s:

    CSS:

    span{
    cursor:url("/images/cursorTextSelect.png") ,default;
    }
    

    HTML:

    <span>This example text fills a line</span>
    <br>
    <span>Some more example text that fills another line.</span>