use*_*544 2 html css flicker hover
我正在尝试在半透明 div 元素上使用背景图像,将鼠标悬停在任何一个元素上都会更改背景颜色。但是,将鼠标移到任一元素上时,我遇到了闪烁效果。
<div class="container">
<div class="test"></div>
<div class="first box"></div>
<div class="third box">third</div>
<div class="second box">second</div>
<div class="fourth box">fourth</div>
<div class="last box">last</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
html, body,
.container {
height: 100%;
min-height: 100%;
}
.box {
width: 191px;
height: 145px;
margin: 4px;
float: left;
background-color: black;
}
.box:hover{
background-color:#EF6939;
opacity: 1;
overflow: hidden;
}
.test:hover{
background-color:#EF6939;
overflow: hidden;
}
.test {
width: 191px;
height: 145px;
margin: 4px;
float: left;
position: absolute;
/* background-image: url(test.png);*/
}
.first {
/* float: left; */
/* background-color: red; */
opacity: 0.1;
}
.second{
/* float: left;*/
/* background-color: green; */
}
.third{
/* float: right; */
/* background-color: blue; */
}
.fourth {
/* float: right; */
/* background-color: #DDDDDD; */
}
.last{
/* float: right; */
/* background-color: yellow; */
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码的链接:http : //jsfiddle.net/YTDyL/
div.test服务于什么目的?
问题是它是重叠的,div.first因为它是绝对定位的。根据您想要的效果,您可能需要div.test向内移动div.first(反之亦然)。如果容器将容纳position: absolute;元素,则无论容器需要定位(相对或绝对或其他)。
两个元素都在竞争:hover,因为它们重叠。因此闪烁(随着:hover鼠标移动,一个获得而另一个失去,然后又回来)。