Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make overlay background click-through-able [duplicate]

Is there a way, in CSS, I can make an element click-through-able. I have an absolutely positioned <div> covering a link. I'd like to be able to click the link through the overlay <div>. The overlay has a mostly transparent background, and the link has no covering pixels.

I've tried background: url('...') transparent, but to no avail.

Here is a JSFiddle demonstrating my problem. The link can be clicked in IE8, but not in FireFox. What I want to do is make an image ticker in the #underlay div. The overlay is so that I can have a background with a gradient from solid to transparent on the bottom and top, so I can make the images sort of 'scroll into nothing', without fading the entire image out at once, if this makes sense (if anyone has an android phone, try scrolling your memos and watch the top/bottom of the screen - the memos fade into nothing).

like image 359
Bojangles Avatar asked Jan 27 '11 21:01

Bojangles


People also ask

How do I allow click through Div?

Just use the pointer-events:none css property to allow click events to go through the element.

What is a button overlay?

Overlay Buttons allow you to create a talk button that lays on top of other apps for any conversation you want. This means that you can keep talking without having Zello in the foreground or use other workarounds.

How do you put a background overlay on a picture?

We can use the property to provide an overlay to the background image. We can use the background-blend-mode property after setting the background image. For example, create a div in HTML. In CSS, set the background image using the url() function and set the no-repeat and fixed values in the background property.

What is CSS overlay?

Overlay means to cover the surface of something with a coating. In other words, it is used to set one thing on the top of another. The overlay makes a web-page attractive, and it is easy to design.


3 Answers

I've fixed your problem by adding pointer-events: none; to the absolute block.

body {    margin: 0;    padding-left: 10px;    font: 20px Arial, sans-serif;    line-height: 30px;  }  a:hover {    color: red;  }  #overlay-blocking,  #overlay-passing{    position: absolute;    height: 30px;    width: 10em;    left: 0;  }    #overlay-blocking {    top: 30px;    background: rgba(0,100,0, .2);        pointer-events: none;  }  #overlay-passing {    top: 0;    background: rgba(100,0,0, .2);      }
<a href="#">Link blocked</a><br>  <a href="#" title="hoverable">Link available</a><br>  <a href="#" title="hoverable">Link available</a><br>        <div id="overlay-blocking"></div>  <div id="overlay-passing"></div>
like image 172
tibalt Avatar answered Nov 05 '22 15:11

tibalt


I don't think it is possible, because an image is still a complete box. But have you tried these Image Maps? Seems like that's what you want.

OTHER OPTION

You could also seperate your image into 2, and make sure that your boxes are not overlaying your link of course.

like image 24
Marnix Avatar answered Nov 05 '22 16:11

Marnix


Perhaps this answer would be of some use to you, if you can nest the overlay inside the link: With only CSS, is it possible to trigger :hover and click events underneath an element?

like image 38
Scott Cranfill Avatar answered Nov 05 '22 16:11

Scott Cranfill