93

How can I combine CSS cursor: not-allowed and pointer-events: none; not-allowed seems not to appear

.cursor-default { cursor: default; }
.cursor-not-allowed { cursor: not-allowed; }
.pointer-events-none { pointer-events: none; }
<button class="cursor-default">cursor-default</button>
<button class="cursor-not-allowed">cursor-not-allowed</button>
<button class="pointer-events-none">pointer-events-none</button>
<button class="cursor-not-allowed pointer-events-none">cursor-not-allowed + pointer-events-none</button>

Small sample, please have a look a the forth button cursor: not-allowed did'nt look the button, but show an looked icon.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • jsfiddle: https://jsfiddle.net/ccddtf8j/1/ –  Oct 10 '17 at 11:29
  • Thanks, I don't unterstand to include jsfiddle link. Sorry –  Oct 10 '17 at 11:31
  • Questions seeking code help must include the shortest code necessary to reproduce it **in the question itself** preferably in a [**Stack Snippet**](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/). – Paulie_D Oct 10 '17 at 11:31
  • 1
    instead of `pointer-events: none;` you can use `disabled="disabled"` – Pedram Oct 10 '17 at 11:37
  • @pedram I locked the button in runtime, by adding a class. –  Oct 10 '17 at 11:40
  • simply you can use, in css: cursor: not-allowed; and using javascript, e=>e.preventDefault(); – Vidurajith Darshana Jun 22 '22 at 11:06

1 Answers1

167

you can't do this because pointer-events: none; disable all mouse functions, but you can do a trick and wrap your button with a div then use cursor: not-allowed; on this.

.pointer-events-none {
    pointer-events: none;
}

.wrapper {
    cursor: not-allowed;
}
<div class="wrapper">
<button class="pointer-events-none">Some Text</button>
</div>

Add CSS cursor property when using "pointer-events: none"

Pedram
  • 15,766
  • 10
  • 44
  • 73