css - 悬停时隐藏绝对定位的div

标签 css position hide

我有这个 html:

<div class="caption">
    <h2><a href="single-image.html">Sun Flower</a></h2>
    <p class="meta-info-font">I took this photo at some bla bla bla.. and some other stuff.</p>
</div>

为什么这行不通:

.caption {
    position: absolute;
    top: 40%;
    left: 0;
    right: 0;
    background-color: rgba(20,19,19,0.94);
    display: none;
}

.caption:hover {
    display: block;
}

最佳答案

.caption {
    position: absolute;
    top: 40%;
    left: 0;
    right: 0;
    background-color: rgba(20,19,19,0.94);
    display: block; /* HERE */
}

.caption:hover {
    display: none; /* HERE */
}

只是默认情况下您的 div 是隐藏的。

关于css - 悬停时隐藏绝对定位的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12286427/

相关文章:

wpf - Telerik RadGrid - 隐藏最左边的列

css - float div 没有按照我想要的方式对齐

html - CSS 3 渐变将嵌套列表限制在父级 UL

html - 背景颜色幻灯片过渡

html - CSS:无法将图像定位在特定位置

android - 我如何从自定义位置开始查看寻呼机并可以从该位置来回滑动?

css - 无序列表CSS定位

html - 使表格看起来类似于 Google Drive 中的表格的 CSS 代码

jQuery - 按值隐藏选项元素

jquery - NiceScroll显示/隐藏