[英]How to make clickable what's behind hover?
A user hovers over glyphicon-globe
image and behind it lies a like button and a comment form. 用户将鼠标悬停在
glyphicon-globe
图像上方,并在其后方glyphicon-globe
一个类似按钮和注释表单。 When a user goes to click on the button or the comment form nothing happens. 当用户单击按钮或注释表单时,将不会发生任何事情。 How can I make clickable what lies behind the globe?
如何使可点击的内容隐藏在全球范围内?
view 视图
<div class="image-container">
<span class="glyphicon glyphicon-globe" style="font-size: 7em; color: white; text-align: center; width: 100%; background-color: #446CB3; border-radius: 4px; padding: 19%;" id="image-foreground"></span>
<div class="text-wrapper">
<div class="like-button">
<%= link_to like_challenge_path(:id => @challenge.id), class: "btn", method: :post do %>
<span class='glyphicon glyphicon-thumbs-up'></span> Like
<% end %>
</div>
<div class="text-background">
<%= render "comments/form" %>
</div>
</div>
</div>
css 的CSS
.image-container {
position: relative;
height: auto;
#image-foreground {
position: absolute;
z-index: 2;
opacity: 1;
&:hover {
opacity: 0;
}
}
}
.text-wrapper {
opacity: 1;
}
no hover 没有悬停
hover 徘徊
There's two ways I'd try. 我尝试了两种方法。 So you know, giving an element
opacity: 0;
所以您知道,给元素
opacity: 0;
won't make it disappear completely. 不会使其完全消失。 It is still there in position but not able to be seen.
它仍然存在,但无法看到。 To have an element removed also use both
opacity: 0;
要删除元素,请同时使用两个
opacity: 0;
and visibility: hidden
in your &:hover
action. 和
visibility: hidden
在&:hover
动作中。
The second way you could do it is stick with opacity: 0
but also set z-index: 0
(or any number below the z-index of the underlying layers. You have the hover working nicely but because it has a higher z-index
than the underlying layers, it is still technically sitting on top of them and covering them, making them unclickable. 第二种方法是坚持
opacity: 0
但还要设置z-index: 0
(或低于基础层的z-index的任何数字。您的鼠标悬停效果很好,但是它具有较高的z-index
而不是底层,从技术上讲,它仍然位于它们之上并覆盖它们,使它们不可点击。
Hope that helps 希望能有所帮助
Also a side note to the answer below, one of the answers here suggested using display: none
in your hover
action. 还要注意以下答案,此处建议使用
display: none
答案之一display: none
hover
操作中display: none
。 display: none
doesn't work for this as once an element is set to display: none
, it is no longer there, not part of the DOM and so breaks the hover action. display: none
对此不起作用,因为一旦将元素设置为display: none
,该元素就不再存在,不再是DOM的一部分,因此中断了悬停操作。
you could do on hover display the blue screen as none. 您可以在悬停时将蓝屏显示为无。
.image-container:hover {
display: none;
}
it that what you wanted ? 那是你想要的吗?
Here was the trick that worked: 这是起作用的窍门:
.hide-globe {
position: absolute;
width: 100%;
background-color: #ccac00;
padding: 100px;
}
.text-wrapper {
position: absolute; // This was essential
opacity: 0;
z-index: 1;
width: 100%;
&:hover {
opacity: 1;
background-color: white; // And this helped make the image seemingly go away
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.