


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 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

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

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

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

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.
