我有以下HTML:
<ul>
<li>
<a href="#">
<h2>title</h2>
</a>
</li>
<li>
<a href="#">
<h2>title</h2>
</a>
</li>
<li>
<a href="#">
<h2>title</h2>
</a>
</li>
</ul>CSS
ul {
list-style: none;
text-align: center;
}
ul li {
position: relative;
float: right;
margin-right: 20px;
width: 30%;
}
ul li {
transition: all 0.3s;
}
ul li:hover {
top: -10px;
}
ul li> a{
color: red;
}问题是,转型不适用于moz,它在webkit上工作。如何以跨浏览器的方式实现这一点?
演示
发布于 2013-08-26 09:45:33
如果元素中没有指定属性的初始值,浏览器就不会在属性上应用transition。因此,将top: 0px添加到ul li将解决这个问题。
ul {
list-style: none;
text-align: center;
}
ul li {
position: relative;
float: right;
margin-right: 20px;
top: 0px; /* this line was added */
width: 30%;
}
ul li {
transition: all 0.3s;
}
ul li:hover {
top: -10px;
}
ul li> a {
color: red;
}<!-- Library included just to avoid prefixes so that users with older browser can view -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<ul>
<li>
<a href="#">
<h2>title</h2>
</a>
</li>
<li>
<a href="#">
<h2>title</h2>
</a>
</li>
<li>
<a href="#">
<h2>title</h2>
</a>
</li>
</ul>
注:我还建议使用与_Green先生在回答中提到的相同的选项(transform)。
发布于 2013-08-26 09:32:36
我不知道为什么firefox属性在火狐中做动画很奇怪,即使它在top中被列为http://www.w3.org/TR/css3-transitions/#properties-from-css-。
无论如何,使用margin-top而不是top在火狐中运行得很好。
但我建议使用transform的"translateX“和"translateY”css属性,而不是使用下一次的定位,因为它是有效的。(由http://www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/推荐)
发布于 2013-08-26 09:04:52
试试这个:
ul li {
/* standard property and other vendor prefixes */
-moz-transition: -moz-transform 0.3s;
}
ul li:hover {
/* standard property and other vendor prefixes */
-moz-transform: translateY(-10px);
}https://stackoverflow.com/questions/18440393
复制相似问题