【发布时间】:2019-07-08 12:11:00
【问题描述】:
我在页面的左角有一个导航栏。导航栏在悬停时已经设置在margin-left: -120px;,它转换为105px,所以我希望在取消悬停元素时平滑返回。
我尝试在 ul、ul li、ul li a 上使用transition,将它们放在不同的类中。没有什么真正适合我...
/* ----- NAVBAR ----- */
ul {
position: fixed;
z-index: 99;
}
.li1{
animation: move1 2s;
}
.li2{
animation: move1 3s;
}
.li3{
animation: move1 4s;
}
.li4{
animation: move1 5s;
}
.li5{
animation: move1 6s;
}
ul li {
text-align: center;
list-style: none;
padding-top: 10px;
margin-left: -120px;
}
ul li a {
text-align: center;
display: block;
text-decoration: none;
height: 30px;
line-height: 30px;
font-size: 12px;
font-weight: 400;
letter-spacing: 5px;
background: #1a2738;
width: 140px;
color: #fff;
text-transform: capitalize;
border-radius: 15px;
}
ul li a:hover {
background: #1a2738;
color: #fff;
animation: move2 1s forwards;
}
@keyframes move1 {
0% {
opacity: 0;
transform: translate(-50px);
}
40% {
opacity: 100;
transform: translate(105px);
}
}
@keyframes move2 {
100% {
transform: translate(105px);
}
}
我希望知道实际问题是什么,请帮助,谢谢!
【问题讨论】:
-
使用过渡而不是关键帧动画 - stackoverflow.com/questions/20586143/…
-
Motaz,请同时提供相关的HTML代码。看到 HTML 和 CSS 代码对这里的每个人都有很大帮助。
标签: css