【发布时间】:2019-03-14 20:29:44
【问题描述】:
这里是新手。
目标是在悬停时显示包含文本的图像。当我将鼠标悬停在图像显示的“测试”容器上时,从技术上讲,我得到了我想要的东西。但是当我将鼠标悬停在“文本”区域上时,它不会显示。任何帮助将不胜感激。
HTML:
<div class="test">
<img class="testimg" src="images/feat-img2.jpg">
<p class="test-text">This is a caption text</p>
</div>
CSS:
.test {
position: relative;
padding: 0;
margin: 0;
width: 100%;
height: 200px;
overflow: hidden;
background: #111111;
}
.test img {
display: block;
max-width: 100%;
height: auto;
opacity: 0;
transition: all 0.3s ease-in-out;
}
.test:hover, .test img:hover {
opacity: 1;
}
.testimg {
width: 100%;
height: auto;
}
.test-text {
display: block;
position: absolute;
width: 100%;
color: #fff;
left: 50%;
bottom: 50%;
padding: 1em;
font-weight: 700;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
【问题讨论】:
-
将悬停 CSS 规则从
.test:hover, .test img:hover更改为.test:hover img -
非常感谢 jla - 我知道这将是错误的地方。抱歉打扰了。