图像被灰色框(数字)隐藏,其大小与图像相同。当悬停时,灰色渐隐并显示图像,过了一段时间后,图像顶部的文字会消失。::将内容放入无花果之前,有什么方法可以避免这种情况?
我开始倒退,在我写出“盒子”的淡出之前写入文本的淡入。但是,箱子的内容(图)放在figcaption标签内,并按照其规则进行设计。为什么会发生这种情况,并解决我的问题?
以下是代码的相关部分。
section figure {
counter-increment: numImg;
display: flex;
position: relative;
}
section figure::before {
background: rgba(0, 0, 0, 0.5);
content: counter(numImg);
position: absolute;
top: 0;
left: 0;
font-size: 2rem;
color: #0e533e;
width: 200px;
height: 200px;
z-index: 3;
line-height: 200px;
text-align: center;
}
section figure:hover figcaption {
transition: opacity .7s ease-in-out;
opacity: 1;
}
section figure figcaption {
text-shadow: 0px 0px 2px white;
font-size: 2em;
text-align: center;
align-content: center;
width: 200px;
z-index: 1;
position: absolute;
top: -0px;
opacity: 0;
}
<section>
<figure>
<img src="http://cheb-room.ru/uploads/cheb/2016/11/w9RC4W-QqXw-200x200.jpg" alt="">
<figcaption>Text that should fade in</figcaption>
</figure>
</section>
我到目前为止发现的唯一的事情是,不透明度影响一切在一个容器中(即在figcaption),但没有任何办法来避免我的柜台现身在无花果。
能不能再解释问题了吗?你是否希望柜台在图像显示之后才显示出来?或者图像没有在悬停中显示?我不确定你描述的确切问题。 – wlh