【发布时间】:2014-07-29 17:18:33
【问题描述】:
首先,很抱歉,如果这个问题已经得到解答,但我在任何地方都找不到。
我试图在将鼠标悬停在 div 上时获得平滑过渡。在这个 div 之上是另一个 div,它在悬停时可见。过渡似乎没有奏效,那么我该如何完成呢? (jquery 代替 CSS,或其他/更好的代码?)
也许还有其他方法可以做到这一点,我希望你们能帮助我。
HTML:
<ul>
<li>
<div class="hover">
<a href="#">
<p>Test</p>
</a>
</div>
<img src="#" alt="img" />
<div class="text">
<p>Test</p>
</div>
</li>
</ul>
CSS:
body { background-color: #eee;
}
ul { margin: 0;
padding: 0;
list-style: none;}
ul li { width: 30.33%;
height: auto;
margin-right: 3%;
padding: 5px;
background-color: #fff;
float: left;
position: relative;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li img { width: 100%;
max-height: 100%;
z-index: 1;
background-color: #ddd;
border: 0;}
.text { width: 100%;
padding-top: 7%;}
.text p { margin: 0 10px;
padding-bottom: 7%;}
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
display: none;}
.hover a { width:100%;
height: 100%;
margin: 0;
padding: 25px;
display: block;
color: #fff;
text-decoration: none;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li:hover > .hover { display: block;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;}
这是代码:http://jsfiddle.net/HAFEx/
提前致谢!
【问题讨论】:
-
过渡应该是什么样的?您是否希望元素淡入?
-
您无法转换
display属性。 -
您很可能希望将
display: none更改为opacity: 0,并将display: block更改为opacity: 1,并进行跨浏览器(旧版IE)等效操作。 -
借鉴 Paulie_D 所说的话,您可以尝试改变不透明度。
标签: css hover transition