首页 > 解决方案 > Div 在 IE 中悬停时消失

问题描述

我不确定这里发生了什么。在 Firefox 和 Chrome 中,这可以正常工作,但在 IE 中不行。我有一个固定的 div (firstdiv),它在悬停时显示另一个 div (hiddendiv)。只要任一 div 悬停在该 div 上,该 div 就应该保持可见。但是,在 IE 中,当您将鼠标悬停在它上面时它会消失。为什么是这样?

我尝试过使用不同的 z-index 值和定位,但我不明白为什么 IE 不能正确处理这个问题。

.firstdiv {
background: red;
position: fixed;
left: 10px;
bottom: 10px;
height: 50px;
width: 50px;
cursor: pointer;
z-index: 1110;
}

.hiddendiv {
background: blue;
position: fixed;
bottom: 60px;
height: 40px;
width: 244px;
display: none;
cursor: pointer;
z-index: 1200;
}

.firstdiv:hover + .hiddendiv {
display: block;
cursor: pointer;
}

.hiddendiv:hover {
display: block;
cursor: pointer;
}
<div class="firstdiv"></div>
<div class="hiddendiv"></div>

标签: htmlcss

解决方案


当我检查 IE 时,它工作正常。

不确定您使用的是哪个版本。不确定您的实际代码与您在此处提供的示例代码相同。

无论如何,下面的代码可能会对您有所帮助。

.firstdiv:hover + .hiddendiv:hover {
display: block;
cursor: pointer;
}

推荐阅读