【发布时间】:2017-03-13 19:14:15
【问题描述】:
我对一些很可能很简单的事情感到困惑,但我想不通。当我将鼠标悬停在图像 1 上时,我希望图像 2 覆盖图像 1。 因此,目标是将图像 1 与包含半透明颜色渐变的图像 2 重叠。我知道这可以通过纯 CSS 以某种方式实现,但我需要这种方式。
以下 CSS 代码取自另一个 Typo3 CMS 网站,并且可以正常工作。
但是,我似乎无法让它在该 Typo3 网站的另一部分/元素上运行,我什至无法让它在像这样的简单基本 HTML 页面上运行。
<!DOCTYPE html>
<html>
<body>
<style>
.container {
height: 300px;
width: 500px;
position: relative;
background-color: red;
}
img {
position: relative;
height: 100%;
width: 100%;
}
.container .hover-second-image-over-first-image:hover {
width:100%;
height:100%;
background-image:url(image_02.jpg);
background-position:top left;
background-repeat: no-repeat;
background-size:100%;
position:absolute;
opacity:0;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
</style>
<div class="container">
<div class="hover-second-image-over-first-image"></div>
<img src="image_01.jpg" />
</div>
</body>
</html>
编辑:
好的,所以“z-index:10;”确实为我修好了。这段代码在这里有效:
.container {
height: 300px;
width: 500px;
position: relative;
background-color: red;
}
img {
position: relative;
height: 100%;
width: 100%;
}
.container .hover-second-image-over-first-image {
width:100%;
height:100%;
background-image:url(image_02.jpg);
background-position:top left;
background-repeat: no-repeat;
background-size:100%;
position:absolute;
z-index:10;
opacity:0;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.container:hover .hover-second-image-over-first-image {
opacity:.3;
}
但我仍然想知道为什么代码之前在没有任何 z-index 位置的其他网站上工作...
【问题讨论】: