Home >Web Front-end >CSS Tutorial >How to Apply Cursor Styles When Disabling Hover Events with `pointer-events: none`?

How to Apply Cursor Styles When Disabling Hover Events with `pointer-events: none`?

Linda Hamilton
Linda HamiltonOriginal
2024-11-05 10:23:02967browse

How to Apply Cursor Styles When Disabling Hover Events with `pointer-events: none`?

Add Cursor Property When Disabling Hover Events with pointer-events: none

Disabling hover events using pointer-events: none can sometimes prevent the application of cursor styles. This is because pointer-events: none effectively makes the element invisible to mouse interactions, including changing the cursor style.

To resolve this issue, the cursor property should be applied to a parent element that contains the element with pointer-events: none. This allows the cursor style to be applied to the parent element while still disabling hover events for the child element.

Example:

HTML:

<div class="container">
  <a href="#">Link</a>
</div>

CSS:

.container {
  cursor: pointer;
}
.container a {
  pointer-events: none;
  color: blue;
}

In this example, the cursor property is applied to the .container class, which contains the link. This allows the cursor to change to a pointer when hovering over the container, even though the link itself has pointer-events: none applied.

Note that there may be browser inconsistencies when using this approach. In IE11, for example, a pseudo element may be required to ensure compatibility. This pseudo element should have its width and height set to 100%, and its position set to absolute, covering the entire area of the parent element.

The above is the detailed content of How to Apply Cursor Styles When Disabling Hover Events with `pointer-events: none`?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn