Button click in my React demo is unresponsive
P粉899950720
2023-08-14 10:26:58
<p>Why is there no response after clicking the button? </p>
<p>My sample code:
https://codesandbox.io/s/gallant-knuth-kwf55c</p>
<p>I checked my code and found no problem. Please help me solve it. </p>
The reason is that since all elements are set using
position:absolute
, the content div overlaps the header.This results in the header being hidden when interacting. So when we click, the click event is actually fired on the content, not the button (see below).
We can take the following methods: