Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we make an element (div) transparent to mouse events? [duplicate]

I want to make an element transparent to events. If I click on it, the element just behind to it get fired that event.

like image 741
ghufranne Avatar asked Sep 29 '14 07:09

ghufranne


People also ask

Which element is used to represent the Transparency of an element in CSS?

CSS Opacity / TransparencyThe opacity property specifies the opacity/transparency of an element.

Which property used to specify the Transparency of an element?

The opacity property sets the opacity level for an element. The opacity-level describes the transparency-level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent.

What is opacity property in CSS?

The opacity CSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency.

What is opacity in HTML?

The CSS opacity property is used to specify the transparency of an element. In simple word, you can say that it specifies the clarity of the image. In technical terms, Opacity is defined as degree in which light is allowed to travel through an object.


2 Answers

Use the pointer-events CSS property :

myElement {     pointer-events: none; } 

Do note browser compatibility: http://caniuse.com/#feat=pointer-events

like image 135
Denys Séguret Avatar answered Sep 19 '22 13:09

Denys Séguret


Yes. Set pointer-events:none; on the element above.

Here's a simple example: When I click on the image the select element opens:

div {      width: 14px;      height: 14px;      position:relative;      top: -18px;      left: 58px;      pointer-events: none;      background: url(http://lorempixel.com/14/14) no-repeat;  }
<select>    <option value="value1">Value 1</option>     <option value="value2" selected>Value 2</option>  </select>  <div></div>

Browser support is good (caniuse): except for IE - where it is only supported in IE11

like image 22
Danield Avatar answered Sep 19 '22 13:09

Danield