


About the weird behavior of pointer-events attribute in css_html/css_WEB-ITnose
In my memory, pointer-events is used for event penetration. In other words, if pointer-events:none is set to the parent element, the parent element will no longer listen to mouse events. Event (similar to touch, click, etc.).
When we need to do this, we usually want to "penetrate" the parent layer. When we directly click on the child element, the parent element will act as if nothing happened. This is information gathered from my previous body of knowledge. It doesn't seem wrong now, but it's incomplete.
It has side effects, or in other words, the application of the above knowledge is conditional. This is indeed the behavior when we apply this (pointer-events:none) attribute to elements that are in a parent-child relationship, but does it still behave like this when we apply it to two block elements in parallel layers?
This problem is caused by the application shown in the screenshot above. I'll give a simplified prototype later. First, let’s briefly introduce the problem of this scene demonstration. The picture above actually has four layers:
The page layer as the page container and the sub-layer composed of flowers and plants under the page. For the convenience of subsequent demonstrations, they are named pagesub layer.
The other layer is the button layer used to turn pages left and right. This layer is parallel to the page layer and is named float layer because it looks like it is floating on the page. There is a layer called floatsub below the float layer, which is used to wrap the small mushroom buttons.
I hope that when I click on the little mushroom, the event on the float layer will not be triggered, so I added pointer-events:none to the float layer; then the problem comes, now I click on the little mushroom and there is no response. . After monitoring, it was found that what was clicked was the flowers and plants layer in the page. I couldn't help but miss my sister. After a fierce pursuit, I finally found true love. Below I will announce this twists and turns process of seeking a sister:
pagesub is the sub-element of page, and floatpage is the sub-element of float. Their positional relationship is as shown in the figure above. The green page is the page layer, and the blue pagesub is the flower layer. The red float is the button layer
and the gray float page is the mushroom layer. (Color-blind friends can just read the text)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> body { text-align: center; } .page { position: absolute; top : 0; left:0; height: 400px; background-color: green; width:500px; z-index: 2; } .float { width: 400px; height: 200px; position: absolute; top:50px; left: 50px; z-index: 3; pointer-events:none; background-color: red; } .pagesub { width: 90%; height: 60%; position: absolute; top:30px; left: 10px; z-index: 4; background-color: blue; color:white; } .floatsub { width:80%; height: 60%; position: absolute; top:33px; left:44px; background-color: gray; z-index: 4; color: white; } </style></head><body><div class="page">page <div class="pagesub"> pagesub </div></div><div class="float">float <div class="floatsub"> float page </div></div></body></html>
According to the above source code, I adjusted it in chrome and found that when I entered the float page ( When viewing elements in the gray) layer, it actually shows a blue pagesub layer. It’s totally unreasonable. There is a picture and the truth:
But when I tried to remove the attribute pointer-events, a miracle happened and everything returned to expectations. Why is this? Note that pointer-events will affect absolutely positioned layers and relationships! Of course, the prerequisite is a parallel relationship, not a parent-child relationship. Using pointer-events on elements in a parallel relationship will cause subsequent elements to be ignored.
Pay attention to what I said here "Absolutely positioned layers and relationships" means that elements that look like they use the pointer-events:none attribute go behind useless elements. As for whether this is really happening at the bottom level, I can't confirm it, but the test results show that this is the case.
In addition to none, let me mention several other attributes of pointer-events:;
Okay, that’s it for this sharing, post it Thank you for your hard work. Those who are rich will support you financially, and those who are good will support you personally. Thank you all!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex
