I wanted to make a button that would go in a U shape horizontally and to do that, I put a white pseudo element on top of the existing button but the problem is that the pseudo-element still is clickable in the parts where it is on top of the button.
At the start, there was a change in the cursor on hover as well but I got around it by putting the cursor to auto and so the cursor change does not happen on the pseudo-element but the click event is still triggered.
This is the css code and the Code Pen link:
https://codepen.io/SawanSunar24/pen/KKxQvWm?editors=1111
.btn {
border: none;
height: 60px;
background-color: #3b82f6;
border-radius: 0 30px 30px 0;
color: white;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 40px;
padding-right: 20px;
position: relative;
overflow: hidden;
cursor: pointer;
}
.btn::before {
background-color: white;
border-radius: 0 100% 100% 0;
bottom: 0px;
left: -20px;
content: "";
display: block;
height: 60px;
cursor: auto;
position: absolute;
width: 40px;
}
I put various other elements on top of the button but they are not clickable and this issue/condition only happens for pseudo elements.
I would appreciate it if someone would tell me a way of getting around this problem, or maybe I am just stupid and this is a bad practice, so a criticism about a better way of doing it would also be helpful.
Thank you.
2
Answers
In my original answer I said you only need to add
pointer-events: none;
to your before element. As pointed out in the other answer, this won’t have your desired effect. Below is a snippet showing how you can use clip-path and a radial gradient instead.Working snippet:
This answer is for the opposite problem but, the same solution can be applied and have your event handler check the
event.target
; if it is the child element do nothing.CodePen