css - 仅通过 CSS 更改悬停内容

标签 css hover swap

我已经看到许多不同的方法来解决以下问题,但它并没有像我希望的那样工作...

我需要制作一个包含多个 div 的 div(主 div)(item-divs)。

每个 item-div 必须显示不同的图片,但是当我将鼠标悬停在某张图片上时,应该隐藏该图片并显示文本 - 在同一个 div 中。

我到底该怎么做?

最佳答案

例如这个变体:

<div class="wrap">
    <div class="child1"></div>
    <div class="child2"></div>
</div>

你的 CSS 应该是:

.wrap:hover > child2{
    opacity: 0;
}

但是静态样式应该是这样的:

.wrap{
    width: 200px;
    height: 300px; /* maybe auto if you want */
    position: relative;
}

.child1{
    width: 100%;
    height: 100%;
    background: lightgreen;
}

.child2{
    width: 100%;
    height: 100%;
    background: #ff3030; /* surely for example */
    position: absolute;
    top: 0;
    left: 0;
}

/* and this block .child2 will be faced. When it's opacity will be 0, you get your effect */

关于css - 仅通过 CSS 更改悬停内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24446714/

相关文章:

jquery - 交换图像,改变宽度和高度

javascript - 您可以使用 jQuery 为当前的 css 值添加旋转吗?

html - CSS - 流畅布局和居中的无表菜单栏

HTML 下拉菜单从左到右而不是直接向下。显示 :block not working

c++ - 正常 block 后检测到堆损坏(#174)

c++ - 从函数交换并返回 Char 数组

html - 在最后一行调整 flex 元素的大小

javascript - OpenLayers 3悬停每次只突出显示一个指定的对象

Android 检测悬停在 GridView 中的按钮上

jquery - 如何在具有悬停事件的 jQuery 动画中正确使用 stop() ?