Css нажать сквозь элемент

How to Click Through a div to its Underlying Elements

Imagine that you have a div the background of which is transparent, along with border. Under this div, you have other different elements. You want to click on these underlying elements through the div. This causes problems for most developers, as they can click underlying elements only in case of clicking the outside of the overlay . If you have such a problem, then this snippet is for you. Let’s dive in and try to do it together.

Add HTML

Add CSS

  • You can solve this problem using the “none” value of the CSS pointer-events property. In the case of using this value, the element will not react to the pointer-events.
  • With the help of the CSS background property put your transparent background.
pointer-events: none; background: url(background);

Example of clicking through a div to its underlying elements:

Using the AlphaImageLoader filter, you can even put a transparent PNG or GIF in the overlay div and click it through a div.

Читайте также:  Windows powershell and python

Example of using the AlphaImageLoader filter:

Another way of solving this problem is disabling pointer-events in a parent element, leaving it enabled for its child elements. This is beneficial when you work with various overlapping div layers, where you want the child elements to react pointer-events, but the parent elements — no.

Here you need to use the “none” value of the pointer-events property for the parent div, and the “auto” value for the child div.

Example of the pointer-events property with the “none” and “auto” values.

.parent < pointer-events:none; > .child < pointer-events:auto; > div ul >0 parent"> li child">li> li child">li> ul> ul >1 parent"> li child">li> li child">li> ul> div>

Источник

How to Click Through an Element on Web

An example of the construction of a web interface similar to Instagram Stories

I’ve been working on the Content Management System for YouVersion Stories. Think something like the fun and interactive Instagram stories, but with a focus on helping people seek intimacy with God every day. In the CMS, I have a preview of the story, so that the admin can see exactly what the story will look like on a device. It did almost everything that the client apps did besides one big thing: navigate between story modules with a tap. I want to be able to navigate between story modules, while also being able to interact with some elements on the module. The tap navigation works like this. Left side: go back. Middle: go forward. Right side: go forward. See the images above. This shows the tap navigation panels. In its current state, if I clicked the reflective answer button «Loving my neighbors», what would happen? I’ll give you a second to think. It would navigate to the next module of the story, instead of selecting that answer button. If only there was a way where I could click through that element to get to the button. CSS pointer-events are here to save the day!

Читайте также:  Http support katharsis ru index php

How do I do it?

An image example of a situation where it seems impossible to an web element because it is covered

The layers of the story go like this: tap navigation > story module. The story module is on top of the navigation. That means it covers the entire tap navigation. On the story module, I added one simple line of CSS.

.story-module  pointer-events: none; > 

That means that any mouse/touch event will go through that element to the next one underneath it. This gives us full access to the tap navigation! There’s still one problem. Nested in the story module are the answer buttons that I wanted to tap, but since all mouse/touch events go to the tap navigation, clicking on an answer won’t work. It’ll only progress the story to the next module. To fix this, just add back the pointer event to the buttons.

.story-module .btn-answer  pointer-events: auto; > 

Here is after we

Viola! Now, we can easily tap the buttons when needed, and then anywhere else on the story to navigate between modules 😄 Check out Stories in the Bible app at https://bible.com/stories

Additional Resources

Источник

Click Through div to Underlying Elements – CSS

Developers can utilize other various elements under a div container. Suppose you want to click on any underlying items that are accessible via the div. Most developers will have severe issues because they can only click underlying items if they click the outer side for the overlaying in the div. To handle such a situation, go for the option of clicking through the created div.

This post will explain the method for clicking through the div to underlying the elements in CSS.

How to Click Through div to Underlying Elements in CSS?

To click through a div to underlying elements in CSS, first, create a main div with a particular name and add an “ ” element for defining the hyperlink, which is utilized for linking from one page to another. Then, insert an “” tag following the same procedure and specify a class name.

Step 1: Create a div Container

First, utilize the “ ” element for creating a “div” container in an HTML file. Then, specify an “id” inside the “div” opening tag with a particular value.

Step 2: Create Nested div Container

Next, make another div container in the first container by following the same procedure.

Step 3: Insert Heading

After that, utilize the HTML heading tag to add a heading. In this scenario, the “ ” heading tag is used.

Step 4: Add an Element for Underlying Elements

Now, insert an “ ” element to link one page with another. To do so, add the “href” attribute inside the “” tag and set the value of this attribute to assign the website link:

Click on the Link

Step 5: Style Main div Container

Access the main div with the help of the attribute selector and name as “.main-content”:

background-color : rgb ( 207 , 250 , 207 ) ;

Now, apply the above given CSS properties:

  • margin” is used for specifying the space around the element’s boundary.
  • border” determines the border outside the defined element.
  • padding” allocates the space inside the defined boundary.
  • background-color” deployed for setting the color at the element’s backside.

As a result, the main container will be styled as follows:

Step 6: Apply “pointer-events” Property

Now, access the nested container using the class name as “.root”:

Then, apply the “pointer-events” to manage the HTML components that react to mouse and touch events. In this scenario, the value of “pointer-events” is set as “none”, which means the element does not react to pointer-events:

Step 7: Access the Child Class

Now, access the “ ” tag with the class name as “.child”. Then, apply the “pointer-events” property and set the value as “auto”:

The “auto” value is utilized for reacting to pointer events like click.

That’s all about clicking through div to underlying elements in CSS.

Conclusion

To click through div to underlying elements, first, make a main div with a particular name and add a class or id attribute. Then, insert the “ ” element and add the class attribute as a child. After that, access the div and apply the “pointer-events” with the value none. Next, access the child attribute and apply “pointer-events” with the value “auto”. This write-up has demonstrated the method for clicking through div to underlying elements.

Источник

Можно ли сделать такой DOM элемент, чтобы все клики проходили сквозь него?

. на элемент лежащий под ним, при этом чтобы этом элемент был виден?

Мне в голову приходит идея о том, чтобы отловить события, на верхнем элементе, и имулировать их на нижний, но есть ли варианты проще?

BorodinKO

Это нужно для того, чтобы передавать события в iframe поверх которого находится надпись.

var listener = function(e) < iframe.postMessage(, '*'); > domElement.addEventListener('mousedown', listener); domElement.addEventListener('mouseup', listener) domElement.addEventListener('mousemove', listener);
window.addEventListener('message', function(e) < var event = document.createEvent ('MouseEvents'); event.initMouseEvent(e.data.type, true, true, window, 1, null, null, e.data.x, e.data.y, false, false, false, false, 0, null); domElement.dispatchEvent(event); >)

Спасибо большое SelenIT2 за pointer-events:none теперь все проесще и нативно

Если попроще, и натуральнее, то можно прикрепить один обработчик к коллекции элементов. Если используешь Jquery, то можно так:

// Укажи селекторы через запятую $("button, a").click(function()< // Do smth >);

riky

непонятна причина зачем, а так наверное правильнее как вы и сказали

непонятно почему это не подходит для вас?

$(document).on('click', '.myClass', function(e)< // . >); $(document).on('click', '.myOtherClass', function(e)< // . >);

то jquery поставит один клик обработчик на document а уже внутри будет проверять кликнули по myClass или myOtherClass и вызовет одну(а может и не одну) из ваших функций.

Источник

HTML/CSS make clickable through transparent DIV layer

When using HTML/CSS to implement beautiful graphic design, we will need to use the transparent DIV what is the DIV html tag with css style ‘background: transparent;’. Just like you I use it and I meet the problem with it many times when I want to keep the transparent layer but I still want to keep the clickable element (button, link, text … ) under the fly layer. So I want to do the magic thing what can make it clickable through transparent DIV

clickable through div layer

Ok, in the case I share you guy this article, I already solved my problem and here is the key CSS

If in your transparent div element have another child elements and you want to make it still clickable, then let add this css

It will keep the parent transparent and click through in the case the child still keep clickable.

Clickable through transparent DIV layer in IE

Our challenge is not end here, we still meet the problem with IE, in this case, you can use this CSS for IE

background:white; opacity:0; filter:Alpha(opacity=0);

If you still meet the problem with too old IE you can use this magic CSS

background:url('transparent.png'); filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='transparent.png', sizingMethod='scale'); background:none !important;

With transparent.png is transparent image with size 1px x 1 px

Cross-browser clickable through transparent DIV layer via javascript library

Actually, the CSS element pointer-events will help your style work on all chrome and firefox version. If you think it ‘s too complex to fire with IE then you can simply use this solution what make pointer-events work in IE

Don’t ask me why, let ‘s tell me your problem. And good luck!

Источник

Оцените статью