简体   繁体   English

覆盖中的CSS链接接管div

[英]CSS link in overlay taking over a div

I have a <div> that contains a link. 我有一个包含链接的<div>

At the bottom right corner of this <div> , I have an overlay element which takes over the whole <div> when hovered. 在这个<div>右下角,我有一个覆盖元素,它在悬停时接管整个<div>

This overlay element also contains a link. 此叠加元素还包含一个链接。

My problem is that the link in the overlying element is not clickable. 我的问题是覆盖元素中的链接不可点击。

The problem is because I use pointer-events: none; 问题是因为我使用pointer-events: none; on class .overlay-content , but if I don't use it, both links become dead. 在类.overlay-content ,但如果我不使用它,两个链接都会死掉。

Please see code here: 请在此处查看代码:

 .panel-default1 { padding-top: 10px; border-radius: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.10); height: 400px; width: 400px; overflow: hidden; margin: 0 auto; position: relative; } .amg-corner-button_wrap { display: block; background-color: #e8c63d; position: absolute; transform: rotate(45deg); right: -320px; bottom: -320px; width: 400px; height: 400px; -moz-transition: all 0.5s ease-out; -o-transition: all 0.5s ease-out; -webkit-transition: all 0.5s ease-out; transition: all 0.5s ease-out; } .amg-corner-button_wrap:hover { transform: rotate(45deg) scale(4); } .overlay-content { pointer-events: none; bottom: 0; color: #333; left: 0; opacity: 0; padding: 30px; position: absolute; height: 100%; width: 100%; box-sizing: border-box; padding: 8px; right: 0; top: 0; -moz-transition: all 0.3s ease-out; -o-transition: all 0.3s ease-out; -webkit-transition: all 0.3s ease-out; transition: all 0.3s ease-out; } .overlay-content h2 { border-bottom: 1px solid #333; padding: 0 0 12px; } .amg-corner-button_wrap:hover~.overlay-content { opacity: 1; -moz-transition: all 0.3s ease-out; -o-transition: all 0.3s ease-out; -webkit-transition: all 0.3s ease-out; transition: all 0.3s ease-out; -moz-transition-delay: 0.3s; -o-transition-delay: 0.3s; -webkit-transition-delay: 0.3s; transition-delay: 0.3s; } 
 <div class="panel panel-default1"> <div class="panel-body"> <a href="#">Link</a> <div class='amg-corner-button_wrap'></div> <div class="overlay-content"> <h2>Image Ink Logo</h2> <a href="#">Link</a> </div> </div> <!-- panel body --> </div> <!-- panel default --> 

Also, here is fiddle . 此外, 这里是小提琴

Is there any way that I can achieve this? 有什么方法可以实现这个目标吗?

can't believe I actually found a pure CSS solution without any drawbacks. 不敢相信我实际上找到了一个没有任何缺点的纯CSS解决方案。

 .panel-default1 { padding-top: 10px; border-radius: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.10); height: 400px; width: 400px; overflow: hidden; margin: 0 auto; position: relative; } .amg-corner-button_wrap { display: block; background-color: #e8c63d; position: absolute; transform: rotate(45deg); right: -320px; bottom: -320px; width: 400px; height: 400px; -moz-transition: all 0.5s ease-out; -o-transition: all 0.5s ease-out; -webkit-transition: all 0.5s ease-out; transition: all 0.5s ease-out; } .wrap:hover .amg-corner-button_wrap { transform: rotate(45deg) scale(4); } .overlay-content { pointer-events: none; bottom: 0; color: #333; left: 0; opacity: 0; padding: 30px; position: absolute; height: 100%; width: 100%; box-sizing: border-box; padding: 8px; right: 0; top: 0; -moz-transition: all 0.3s ease-out; -o-transition: all 0.3s ease-out; -webkit-transition: all 0.3s ease-out; transition: all 0.3s ease-out; } .overlay-content h2 { border-bottom: 1px solid #333; padding: 0 0 12px; } .wrap:hover .amg-corner-button_wrap ~ .overlay-content { pointer-events: auto; opacity: 1; -moz-transition: all 0.3s ease-out; -o-transition: all 0.3s ease-out; -webkit-transition: all 0.3s ease-out; transition: all 0.3s ease-out; -moz-transition-delay: 0.3s; -o-transition-delay: 0.3s; -webkit-transition-delay: 0.3s; transition-delay: 0.3s; } 
 <div class="panel panel-default1"> <div class="panel-body"> <a href="#">Link</a> <div class="wrap"> <div class='amg-corner-button_wrap'></div> <div class="overlay-content"> <h2>Image Ink Logo</h2> <a href="#">Link</a> </div> </div> </div> <!-- panel body --> </div> <!-- panel default --> 

JSFiddle 的jsfiddle

Instead of listening to the :hover event on the corner-button, listen to it on a parent element. 而不是在角落按钮上听取:hover事件,而是在父元素上听它。 Since the :hover will be dispatched regardless of the mouse interaction of the elements' children, it is possible to set pointer-events: auto to the children containing links (overlay-content), once the corner-button has been hovered. 由于:hover将被调度而不管元素子项的鼠标交互如何,一旦角落按钮被悬停,就可以设置pointer-events: auto到包含链接的子项(overlay-content)。 Now, that the overlay-content is hoverable and since it's a child of the wrapping div, it will cause the :hover to stay active over the whole wrapping div. 现在,覆盖内容是可以缓存的,因为它是包装div的子代,它将导致:hover在整个包装div上保持活动状态。

I would recommend using JS style swapping instead of CSS pointer events for this problem. 我建议使用JS样式交换而不是CSS指针事件来解决这个问题。 You need to trigger one change to your css when you mouse over the bottom corner, and a separate event when you mouse out of the container. 当鼠标悬停在底角时,您需要触发对css的一次更改,当您将鼠标移出容器时,需要单独执行一次更改。 I do not believe CSS gives you that kind of conditional control. 我不相信CSS会给你那种条件控制。

Here is half a solution using animations instead of transitions. 这是使用动画而不是过渡的半个解决方案。 This works for when you hover on to the amg-corner-button_wrap but not when you move off it. 当你将鼠标悬停在amg-corner-button_wrap上时,这种方法有效,但是当你移开它时则不适用。 I'm a bit new to animations so hopefully someone here who knows more maybe able to help you with the second half. 我对动画有点新意,所以希望有些人知道更多可能会帮助你进行下半场。

There is also a weird visual in here if you hover on the amg-corner-button_wrap and hover off mid transition. 如果你将鼠标悬停在amg-corner-button_wrap上并悬停在过渡中间,那么这里还有一个奇怪的视觉效果。 The reason for this is that I added a background color to overlay-content so when it's fading in and you mouse off amg-corner-button_wrap the swipe starts to reverse before the fade is complete. 这样做的原因是我为叠加内容添加了背景颜色,因此当它淡入并且你将鼠标移开amg-corner-button_wrap时,滑动在淡入淡出完成之前开始反转。

Anyway, hope this 50% solution helps you or others drive this to 100%! 无论如何,希望这个50%的解决方案可以帮助您或其他人将其驱动至100%! Have to run to a meeting, good luck :-) 不得不跑去开会,祝你好运:-)

 @keyframes example { 0% { visibility: hidden; opacity: 0; } 1% { visibility: visible; opacity: 0; } 100% { visibility: visible; opacity: 1; } } .panel-default1 { padding-top: 10px; border-radius: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.10); height: 200px; width: 200px; overflow: hidden; margin: 0 auto; position: relative; } .amg-corner-button_wrap { display: block; background-color: #e8c63d; position: absolute; transform: rotate(45deg); right: -120px; bottom: -120px; width: 200px; height: 200px; -moz-transition: all 0.5s ease-out; -o-transition: all 0.5s ease-out; -webkit-transition: all 0.5s ease-out; transition: all 0.5s ease-out; } .overlay-content { visibility: hidden; opacity: 0; background-color: #e8c63d; bottom: 0; color: #333; left: 0; padding: 30px; position: absolute; height: 100%; width: 100%; box-sizing: border-box; padding: 8px; right: 0; top: 0; } .overlay-content h2 { border-bottom: 1px solid #333; padding: 0 0 12px; } .overlay-content~.amg-corner-button_wrap, .amg-corner-button_wrap:hover { transform: rotate(45deg) scale(4); } .amg-corner-button_wrap:hover~.overlay-content, .overlay-content:hover { animation-name: example; animation-duration: 0.3s; animation-timing-function: linear; animation-delay: 0.3s; animation-fill-mode: both; } 
 <div class="panel panel-default1"> <div class="panel-body"> <a href="#" onclick="alert('outer')">Link</a> <div class='amg-corner-button_wrap'></div> <div class="overlay-content"> <h2>Image Ink Logo</h2> <a href="#" onclick="alert('inner')">Link</a> </div> </div> <!-- panel body --> </div> <!-- panel default --> 

Here's a working fiddle for a css and html only change: https://jsfiddle.net/y2auh7gn/4/ . 这里有一个css和html改变的工作小提琴: https//jsfiddle.net/y2auh7gn/4/

It separates the link from overlay-content and places it where it's supposed to be with position: absolute . 它将链接与overlay-content分开,并将其放置在与position: absolute We need to move the link out of overlay-content so that when we hover over it the overlay doesn't disappear. 我们需要将链接移出overlay-content以便当我们将鼠标悬停在overlay-content上时,叠加层不会消失。

There's a side-effect where the link pops out with the corner piece. 有一个副作用,链接弹出角落。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM