Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/CSS: Make a div "invisible" to clicks?

Tags:

html

css

events

For various reasons, I need to put a (mostly) transparent <div> over some text. However, this means that the text can't be clicked (eg, to click links or select it). Would it be possible to simply make this div "invisible" to clicks and other mouse events?

For example, the overlay div covers covers the text, but I would like to be able to click/select the text through the overlay div:

<div id="container">     <p>Some text</p>     <div id="overlay" style="position: absolute; top: 0;                              left: 0; width: 100%; height:100%">         ... some content ...     </div>  </div> 
like image 321
David Wolever Avatar asked Aug 21 '10 18:08

David Wolever


People also ask

How do I make div invisible in CSS?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden. display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.

How do you make a div invisible and visible in HTML?

Making it invisible with visibility still makes it use up space. Rather try set the display to none to make it invisible, and then set the display to block to make it visible.

How do I allow click through div?

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

How do I hide a div?

We hide the divs by adding a CSS class called hidden to the outer div called . text_container . This will trigger CSS to hide the inner div.


2 Answers

It can be done using CSS pointer-events. This property is supported in Firefox 3.6+, Chrome 2+, IE 11+, and Safari 4+. Unfortunately, I don't have knowledge of a cross-browser workaround.

#overlay {   pointer-events: none; } 
like image 51
Ionuț G. Stan Avatar answered Sep 30 '22 21:09

Ionuț G. Stan


It can be done by refiring the event after you temporarily hide the overlay.

See the first answer to this question: HTML "overlay" which allows clicks to fall through to elements behind it

like image 37
Joeri Sebrechts Avatar answered Sep 30 '22 22:09

Joeri Sebrechts