【问题标题】:Hover Issue - Show Image On Hover [duplicate]悬停问题 - 悬停时显示图像 [重复]
【发布时间】: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;
}

HOVERED OVER TEXT & ORIGINAL STATE

HOVERED OVER CONTAINER

【问题讨论】:

  • 将悬停 CSS 规则从 .test:hover, .test img:hover 更改为 .test:hover img
  • 非常感谢 jla - 我知道这将是错误的地方。抱歉打扰了。

标签: html css


【解决方案1】:

将此属性添加到您的测试文本类

pointer-events: none;

【讨论】:

    猜你喜欢
    • 2017-02-19
    • 1970-01-01
    • 2020-10-13
    • 2016-03-17
    • 2014-05-14
    • 2014-03-28
    • 2017-02-17
    • 2017-01-13
    • 2019-05-12
    相关资源
    最近更新 更多