8

This is the HTML

<li id="nav1" class="navs"><a unselectable="on" draggable="false" class="Navigation" href="http://youtube.com">YouTube</a></li>

This is the CSS

.navs:after {
  content: "";
  position: absolute;
  top: 0;  left: 0;  right: 0;  bottom: 0;
  background: #0d0d0d;
  opacity: 0.5;
  transform: scaleY(0);
  transform-origin: 0 100%;
  transition: all .2s ease-out;
}
.navs:hover:after{
  transform: scaleY(1);
}
.navs:active:after{
    background: #FFFFFF;
}

I think the reason why i can't click the button is because when i click the button, the overlay forms. I do not want to remove the overlay though. Is there any way to click through the overlay?

6
  • add style=" z-index:99999999999!important;" to the bottom you want to be on a higher level so you can click Commented Apr 28, 2016 at 23:32
  • 4
    Don't use !important - make sure your selector is as specific as it needs to be instead. And there's no need to go crazy on the z-index - set it to the maximum value it needs to be right now; you can always increase it later if necessary.
    – Bobby Jack
    Commented Apr 28, 2016 at 23:38
  • 2
    @HatemAhmed Wow... Could you have given any worse advice? Wow.... Commented Apr 29, 2016 at 0:34
  • my advice was copied into a two upvotes answer , @Bobby Jack giving a high value to the z-index save time and effort ,if he used inline styling then there might be no use for important however if he used a class then to ensure that the z-index won't be overwritten it's recommended to use !important Commented Apr 29, 2016 at 0:40
  • @HatemAhmed I neglected to mention that pointer-events is a cleaner solution. Don't use inline styling eiither, altough initially it might save time, moving styles in an external site speeds up the site (parallel download, allows caching, etc) and makes maintenance much easier in the future.
    – molbal
    Commented Apr 29, 2016 at 22:53

3 Answers 3

35

Option one

You can give your element a higher z-index. This will move your button above the overlay, so you will be able to click it

Option two

You can disable all mouse events on your overlay using pointer-events:none; so the click event will 'fall through' it and the button will register it

Edit: Use pointer-events when you can, let z-index be your backup plan. If you fall back to it, I suggest that you don't use it inline, but write a specific selector for it in your CSS.

8
  • 1
    Thank you! It was really helpful!
    – REVENTONMC
    Commented May 2, 2016 at 22:03
  • can you explain how to give the mouse a higher z-index? Commented Jan 16, 2020 at 21:01
  • @crashspringfield Sorry, element, not mouse. It was a brainfart.
    – molbal
    Commented Jan 19, 2020 at 10:42
  • 2
    AHHHHH!!! I understood pointer-events backwards. I thought none meant it would allow none, not that it would handle none itself. Funny, I was looking for the opposite of this question and your answer got me there.
    – Yatrix
    Commented Mar 27, 2020 at 13:49
  • 3
    The style "pointer-events:none;" seems to be the important part (for this problem, for me anyway). Great short question and great answer!
    – Pierre
    Commented Aug 28, 2020 at 13:58
1

It could be many different things... Definitely try to check if you've used any z-index properties for other elements that are the parents of the element. I encountered the exact same problem and I fixed it by troubleshooting: what I did was pull up a javascript file and console log the target className of where I was clicking (can be done by:

    window.addEventListener('click' , (e) => {
        const target = e.target.className; 
        console.log(target);
    })

)

Once I did that, click on the button that doesn't seem to be working. Make sure to add a class to your button before this and check if the class is displayed properly. Sometimes, in my case, I had to move the console out of the window.

From this, I found my SVG Animation was actually taking up invisible space that covered the button. All I had to do to fix this problem was give the SVG a z-index of -1.

Hope this helped! I know I took a long time to find a solution so I hope my solution can help others too.

Note: Also check your pointer events (make sure it isn't set to none) for the button and other elements

0

use span instead of before and after, something like

<a href="my link"><img  class="" src="my_image" alt="">
<span class="rig-overlay"></span>
<span class="rig-text">
<span>name</span>
<span>function</span>
</span>
</a>

the span will not cover the clickable region

Not the answer you're looking for? Browse other questions tagged or ask your own question.