css - child 在悬停时与 parent 的 sibling 重叠

标签 css hover overlap

所以,这是第一个 div:

<div id="parent">
<a>
<div>
<img />
<h3 id="important_text">text</h3>
</div>
</a>
</div>

第二个 div 结构大致相同......

<div id="sibling">
<a>
<div>
<img />
<h3 id="important_text_n2">text</h3>
</div>
</a>
</div>

我想要的: 当我悬停 #parent 时,我想要 #important_text(只是 h3#important_text,而不是整个 div! ) 与 #sibling(实际上是他的 child img)重叠。当我不悬停在 #parent 上时,我希望 #sibling#parent 重叠。

我已经用 z-index 试过了,但我就是无法让 #important_text 重叠其父级的兄弟(#sibling ).


编辑:

使用(不工作的 CSS):

#parent {
z-index: 5;
}
#sibling {
z-index: 15;
}
/* option 1 */
#parent:hover a div h3 {
    z-index: 20;
}
/* option 2 ... here I wanted to decrease the sibling img's z-index to a value between #parent and #important_text, but I didn't work either. */

最佳答案

给H3元素一个绝对位置。示例:

CSS:

h3{
   position:absolute;
   margin-top: -20px;
}

关于css - child 在悬停时与 parent 的 sibling 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18856574/

相关文章:

javascript - 单击输入字段触发窗口调整大小

javascript - 收集所有包含某种颜色的 CSS 设置

html - 覆盖悬停链接 [CSS/HTML]

css - 创建悬停在图像框上

android - Recyclerview 内的重叠 View

android - 如何滚动 float 操作菜单的范围

html - 如何细化 CSS 媒体类型和属性?

html - 如何设置 tinymce 文本区域的高度?

javascript - 有没有办法检测我是否将鼠标悬停在文本上?

css - 悬停时将 <a> 位置更改为 "absolute"(以显示完整措辞)