html - Css 灰度并使用 :after 在其上设置图像

标签 html css

有一张id为img1的图片,我需要在上面放一张id为img2的图片。当鼠标悬停在 #img1 上时,我需要它是黑白的,但 #img2 不应该是。

这是 JsFiddle Link .

它有效,但问题是当鼠标经过 #img2 时,grayScale#img1

中移除

最佳答案

简单替换

img:hover {

在你的 CSS 中,使用:

div:hover img {

参见:

div:hover img {
  filter:gray; /* IE6-9 */
-webkit-filter:grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
-moz-filter: grayscale(100%);
-o-filter: grayscale(100%);
  filter: grayscale(100%);
}

img {
  position: relative;
}

div {
  display: inline-block;
  position: relative;
}

div:after {
  background-image: url("http://sk.uploads.im/t/yJtie.png");
  top: 10px;
  background-repeat: no-repeat;
  right: 5px;
  position: absolute;
  display: inline-block;
  content: " ";
  width: 230px;
  height: 230px;
}
<div>
  <img src="http://www.xenergie.com/wp-content/uploads/2015/05/nature.jpg" />
</div>

关于html - Css 灰度并使用 :after 在其上设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34025521/

相关文章:

flash - 为什么使用 HTML5 Canvas 创建内容比使用 Flash 创作要复杂得多?

javascript - jQuery Cycle 插件 : centering background images when browser is resized

html - 垂直对齐绝对定位元素与 flexbox

jquery - 如何居中对齐向下箭头?

css - 我如何为不同的组件使用不同的 css 文件 React 具有相同的类名

css - 如何将 CSS 动画导出为动画 PNG、gif 或 WEBP *具有透明度*?

html - 有没有办法在本地主机中设置表单输入的字体系列?

css - IE9 - 位置 : relative; hover issue

jquery - 尝试使用 CSS 和 JQUERY 使多个背景图像在幻灯片中循环

javascript - Rubaxa 可使用 polymer 排序/拖放不起作用,具体取决于显示 :