jquery - 如何在悬停时显示图像之上的图像

标签 jquery html css angularjs

我知道这个问题可能已经被回答过几次了。但我需要一个适用于任何图像的解决方案。

我有一个包含 4 张图像的作品集。所以它显示图像,我想在悬停时显示 Github Logo 的图像。

我已经找到了:

a:hover:before {
  content: '';
  display: block;
  background: rgba(255, 0, 0, .5); /* your background */
  width: 500px;
  height: 500px; 
  position: absolute;
  top: 0;
  right: 0;
}

但它需要宽度和高度。我的图像没有相同的高度,因此我需要一个 css/jQuery/Angular 代码来适合悬停的图像。

谢谢!

最佳答案

试试这个,它总是会覆盖它的父级。您可以编辑背景位置以满足您的需要。

a:hover:before {
      content: '';
      display: block;
      background: url('img-path.png') no-repeat;
      background-position: right bottom;
      width: 100%;
      height: 100%; 
      position: absolute;
      top: 0;
      right: 0;
    }

编辑:悬停的 a 标签应使用 position:relative;

关于jquery - 如何在悬停时显示图像之上的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26818431/

相关文章:

jquery - 为什么 jQuery.get ('/home/user/0/0a.html' ) 在使用文件 : rather than http:? 时失败

jquery - 如何使用 html5 css jquery 动画使 div 中的图像向下拖动?

javascript - 同时突出显示图像上的文本和多边形形状

javascript - steemit.com upvote 按钮的动画效果如何?

javascript - 无法实现 jQuery slider

php - 如何在 Stack Overflow 上实现类似的 "interesting tags"功能?

jquery ui 可排序 : How to get current index with id and old index with id and pass parameter in ajax in update event

html - Hash(#) 链接导致内容跳转 - 为什么?

javascript - 移动网页的 Twitter 身份验证?

html - 水平滚动的 svg 元素?