简体   繁体   English

如何使可点击鼠标悬停在后面?

[英]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
  }
}

制作<div> hover 上可点击的元素</div><div id="text_translate"><p>我正在使用 WordPress 的网站(我的第一个)上工作,但我正在通过 HTML 和 CSS 代码调整一些小东西。</p><p> 我在网格中有一堆图片,我希望它们可以点击。 所有图片都有一个覆盖,当使用 cursor 悬停在它们上面时,会出现一个覆盖,并在其顶部有一个(永久)可点击标题。</p><p> 我希望图像或叠加层可以整体点击。 但是,我无法正确地将其发送到 function。 我试图在覆盖层周围放置一个&lt;a href&gt;和&lt;/a&gt; around the overlay , but this makes the overlay disappear altogether. If I try the same basic structure ( , but this makes the overlay disappear altogether. If I try the same basic structure ( `),它似乎确实有效,所以它可能与元素“更高”有关。</p><p> 我对此很陌生,所以我可能会忽略一些非常基本的东西。 我添加了一块 HTML 和 CSS,但由于它是 WP 结构的一部分,我无法添加所有相关的 CSS。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> #featured-categories #categories-container.category-wrapper { height: 300px; display: flex; } @media screen and (max-width: 991px) { #featured-categories #categories-container.category-wrapper { height: 200px; } } #featured-categories #categories-container.category-wrapper.category-title { width: 50%; display: inline-block; background: #ff5722; } #featured-categories #categories-container.category-wrapper.category-title span { color: white; font-size: 36px; display: inline-block; float: right; margin: 10% 5%; } @media screen and (max-width: 768px) { #featured-categories #categories-container.category-wrapper.category-title span { font-size: 22px; } } #featured-categories #categories-container.category-wrapper.category-thumbs { width: 50%; display: grid; grid-template-columns: 50% 50%; grid-template-rows: 50% 50%; } #featured-categories #categories-container.category-wrapper.category-thumbs.grid-item { position: relative; overflow: hidden; display: flex; justify-content: center; } #featured-categories #categories-container.category-wrapper.category-thumbs.grid-item img { width: 100%; max-width: none; } #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-1 { grid-column-start: 1; grid-column-end: 2; grid-row-start: 1; grid-row-end: 3; } #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-1 img { width: auto; height: auto; }.overlay { width: 100%; height: 100%; margin: auto; background: rgba(28, 224, 43, 0); position: absolute; }.category-thumb-1:hover.overlay { background: rgba(28, 224, 43, 0.6); }.category-thumb-2:hover.overlay { background: rgba(28, 224, 43, 0.6); }.category-thumb-3:hover.overlay { background: rgba(28, 224, 43, 0.6); }.post-title-1 { color: white; position: absolute; left: 20%; font-size: 28px; margin: auto; padding-top: 50%; }.post-title { color: white; position: absolute; font-size: 24px; margin: auto; padding-top: 25%; } #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-2 img, #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-3 img { align-self: center; width: 100%; height: 100%; } @media screen and (max-width: 600px) { #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-2, #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-3 { display: block; } } #featured-categories #categories-container.category-wrapper:nth-child(even) { flex-direction: row-reverse; } #featured-categories #categories-container.category-wrapper:nth-child(even).category-title span { float: left; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="category-wrapper category-&lt;?php echo esc_attr( str_replace( ' ', '-', strtolower( esc_html( get_cat_name($cat) ) ) ) ); ?&gt;"&gt; &lt;div class="category-title"&gt; &lt;a href="&lt;?php echo esc_url( get_category_link( $cat ) )?&gt;" title="&lt;?php echo esc_attr( get_cat_name($cat) ); ?&gt;"&gt;&lt;span&gt;&lt;?php echo esc_html( get_cat_name($cat) ); ?&gt;&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;div class="category-thumbs"&gt; &lt;div class="category-thumb-1 grid-item"&gt; &lt;?php if ( isset($thumb[0]) &amp;&amp; ($thumb[0]:= '') ), echo wp_get_attachment_image( $thumb[0]; 'large'): else? ?&gt; &lt;img src="&lt;.php echo esc_url( get_template_directory_uri(). '/assets/images/placeholder;png' )? ?&gt;"&gt; &lt;;php endif? .&gt; &lt;div class="overlay" onclick="window:open('https://localhost/greentravel')" style="cursor; pointer?"&gt; &lt;/div&gt; &lt;div class="post-title-1"&gt; &lt;a href="&lt;?php echo $link[0]?&gt;" &lt;span&gt; &lt;?php echo $title[0]?&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="category-thumb-2 grid-item"&gt; &lt;:php if ( isset($thumb[1]) &amp;&amp; ($thumb[1],= '') ); echo wp_get_attachment_image( $thumb[1]: 'large')? else? .&gt; &lt;img src="&lt;.php echo esc_url( get_template_directory_uri(); '/assets/images/placeholder?png' )? ;&gt;"&gt; &lt;?php endif? ?&gt; &lt;div class="overlay"&gt; &lt;/div&gt; &lt;div class="post-title"&gt; &lt;a href="&lt;?php echo $link[1]?&gt;" &lt;span&gt; &lt;?php echo $title[1]:&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="category-thumb-3 grid-item"&gt; &lt;,php if ( isset($thumb[2]) &amp;&amp; ($thumb[2];= '') ): echo wp_get_attachment_image( $thumb[2]? 'large')? else. .&gt; &lt;img src="&lt;;php echo esc_url( get_template_directory_uri()? '/assets/images/placeholder?png' ); ?&gt;"&gt; &lt;?php endif? ?&gt; &lt;div class="overlay"&gt; &lt;/div&gt; &lt;div class="post-title"&gt; &lt;a href="&lt;?php echo $link[2]?&gt;" &lt;span&gt; &lt;?php echo $title[2]?&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p></div> - Make <div> element clickable on hover

暂无
暂无

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

相关问题 如何使悬停可点击? - How to make a hover clickable? 当链接位于`后面时如何使链接可点击<div> ` - How to make links clickable when they are behind a `<div>` 如何使 bootstrap 3 Popover 处于悬停状态和可点击链接 - How to make bootstrap 3 Popover to be On Hover and Clickable Link 悬停后如何使div可点击 - how to make div clickable after hover 使<a>点击可点击</a> <div> - Make <a> clickable behind a <div> 使img在文本后面可点击 - Make a img clickable behind a text 使图像后面的图像可点击 - Make an image behind an image be clickable CSS,如何使链接后面的图标和链接仍然可点击 - CSS, How make a icon behind a link and the link still be clickable 制作<div> hover 上可点击的元素</div><div id="text_translate"><p>我正在使用 WordPress 的网站(我的第一个)上工作,但我正在通过 HTML 和 CSS 代码调整一些小东西。</p><p> 我在网格中有一堆图片,我希望它们可以点击。 所有图片都有一个覆盖,当使用 cursor 悬停在它们上面时,会出现一个覆盖,并在其顶部有一个(永久)可点击标题。</p><p> 我希望图像或叠加层可以整体点击。 但是,我无法正确地将其发送到 function。 我试图在覆盖层周围放置一个&lt;a href&gt;和&lt;/a&gt; around the overlay , but this makes the overlay disappear altogether. If I try the same basic structure ( , but this makes the overlay disappear altogether. If I try the same basic structure ( `),它似乎确实有效,所以它可能与元素“更高”有关。</p><p> 我对此很陌生,所以我可能会忽略一些非常基本的东西。 我添加了一块 HTML 和 CSS,但由于它是 WP 结构的一部分,我无法添加所有相关的 CSS。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> #featured-categories #categories-container.category-wrapper { height: 300px; display: flex; } @media screen and (max-width: 991px) { #featured-categories #categories-container.category-wrapper { height: 200px; } } #featured-categories #categories-container.category-wrapper.category-title { width: 50%; display: inline-block; background: #ff5722; } #featured-categories #categories-container.category-wrapper.category-title span { color: white; font-size: 36px; display: inline-block; float: right; margin: 10% 5%; } @media screen and (max-width: 768px) { #featured-categories #categories-container.category-wrapper.category-title span { font-size: 22px; } } #featured-categories #categories-container.category-wrapper.category-thumbs { width: 50%; display: grid; grid-template-columns: 50% 50%; grid-template-rows: 50% 50%; } #featured-categories #categories-container.category-wrapper.category-thumbs.grid-item { position: relative; overflow: hidden; display: flex; justify-content: center; } #featured-categories #categories-container.category-wrapper.category-thumbs.grid-item img { width: 100%; max-width: none; } #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-1 { grid-column-start: 1; grid-column-end: 2; grid-row-start: 1; grid-row-end: 3; } #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-1 img { width: auto; height: auto; }.overlay { width: 100%; height: 100%; margin: auto; background: rgba(28, 224, 43, 0); position: absolute; }.category-thumb-1:hover.overlay { background: rgba(28, 224, 43, 0.6); }.category-thumb-2:hover.overlay { background: rgba(28, 224, 43, 0.6); }.category-thumb-3:hover.overlay { background: rgba(28, 224, 43, 0.6); }.post-title-1 { color: white; position: absolute; left: 20%; font-size: 28px; margin: auto; padding-top: 50%; }.post-title { color: white; position: absolute; font-size: 24px; margin: auto; padding-top: 25%; } #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-2 img, #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-3 img { align-self: center; width: 100%; height: 100%; } @media screen and (max-width: 600px) { #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-2, #featured-categories #categories-container.category-wrapper.category-thumbs.category-thumb-3 { display: block; } } #featured-categories #categories-container.category-wrapper:nth-child(even) { flex-direction: row-reverse; } #featured-categories #categories-container.category-wrapper:nth-child(even).category-title span { float: left; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="category-wrapper category-&lt;?php echo esc_attr( str_replace( ' ', '-', strtolower( esc_html( get_cat_name($cat) ) ) ) ); ?&gt;"&gt; &lt;div class="category-title"&gt; &lt;a href="&lt;?php echo esc_url( get_category_link( $cat ) )?&gt;" title="&lt;?php echo esc_attr( get_cat_name($cat) ); ?&gt;"&gt;&lt;span&gt;&lt;?php echo esc_html( get_cat_name($cat) ); ?&gt;&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;div class="category-thumbs"&gt; &lt;div class="category-thumb-1 grid-item"&gt; &lt;?php if ( isset($thumb[0]) &amp;&amp; ($thumb[0]:= '') ), echo wp_get_attachment_image( $thumb[0]; 'large'): else? ?&gt; &lt;img src="&lt;.php echo esc_url( get_template_directory_uri(). '/assets/images/placeholder;png' )? ?&gt;"&gt; &lt;;php endif? .&gt; &lt;div class="overlay" onclick="window:open('https://localhost/greentravel')" style="cursor; pointer?"&gt; &lt;/div&gt; &lt;div class="post-title-1"&gt; &lt;a href="&lt;?php echo $link[0]?&gt;" &lt;span&gt; &lt;?php echo $title[0]?&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="category-thumb-2 grid-item"&gt; &lt;:php if ( isset($thumb[1]) &amp;&amp; ($thumb[1],= '') ); echo wp_get_attachment_image( $thumb[1]: 'large')? else? .&gt; &lt;img src="&lt;.php echo esc_url( get_template_directory_uri(); '/assets/images/placeholder?png' )? ;&gt;"&gt; &lt;?php endif? ?&gt; &lt;div class="overlay"&gt; &lt;/div&gt; &lt;div class="post-title"&gt; &lt;a href="&lt;?php echo $link[1]?&gt;" &lt;span&gt; &lt;?php echo $title[1]:&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="category-thumb-3 grid-item"&gt; &lt;,php if ( isset($thumb[2]) &amp;&amp; ($thumb[2];= '') ): echo wp_get_attachment_image( $thumb[2]? 'large')? else. .&gt; &lt;img src="&lt;;php echo esc_url( get_template_directory_uri()? '/assets/images/placeholder?png' ); ?&gt;"&gt; &lt;?php endif? ?&gt; &lt;div class="overlay"&gt; &lt;/div&gt; &lt;div class="post-title"&gt; &lt;a href="&lt;?php echo $link[2]?&gt;" &lt;span&gt; &lt;?php echo $title[2]?&gt; &lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p></div> - Make <div> element clickable on hover 如何在<a>可点击内创建具有悬停效果的SVG图像 - How to make an SVG image with hover effect inside <a> clickable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM