Menu

pointer-events: none doesn't disable an element. It hands the press to whatever is underneath.
📰

pointer-events: none doesn't disable an element. It hands the press to whatever is underneath.

DEV Community: css·DevNash·14 days ago
#Nk5p9tkj
#devtocss#devto#dev#card#press
Reading 0:00
15s threshold

In a fanned hand of cards, I pressed a card I wasn't allowed to play, and the game played a different card: the one lying under it. The click handler was fine. The card I pressed had pointer-events: none , and that property doesn't stop a press. It takes the element out of hit-testing, the step where the browser works out which element is under the pointer, so the press goes to the next element down, and in a fan the next element down is the neighbouring card.

This post has the minimal repro, a table of where the press lands in Chromium, Firefox and WebKit for five ways of switching an element off, and the fix.

The repro

<!doctype html> <style> .hand { position : relative ; height : 140px ; margin : 20px ; } .card { position : absolute ; top : 0 ; width : 80px ; height : 120px ; } .card :nth-child ( 1 ) { left : 0 ; } .card :nth-child ( 2 ) { left : 40px ; } .card :nth-child ( 3 ) { left : 80px ; } .off { pointer-events : none ; opacity : .5 ; } </style> <div class= "hand" > <button class= "card" id= "a"…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.