【发布时间】:2020-05-15 07:34:46
【问题描述】:
目前,我正在尝试制作一个环绕链接的动画边框框,但是一旦我将鼠标悬停在鼠标上,动画仅适用于伪元素的一个实例,而不适用于两者。写在其他作品之上的实例。
我不知道这有什么问题,因为我也找不到问题所在。两个伪元素都获得了 Content 集,我真的不知道出了什么问题。
这里是代码
nav a {
text-decoration: none;
color: white;
width: 100px;
height: 50px;
padding: 25px;
position: relative;
}
nav a::before {
content: "";
position: absolute;
top: -2px;
left: -2px;
width: 0;
height: 0;
padding: 0;
background: transparent;
border: 2px transparent solid;
}
nav a:hover::before {
animation: animate 0.5s linear forwards;
}
@keyframes animate
{
0% {
width: 0;
height: 0;
border-top-color: white;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
}
50% {
width: 100%;
height: 0;
border-top-color: white;
border-right-color: white;
border-bottom-color: transparent;
border-left-color: transparent;
}
100% {
width: 100%;
height: 100%;
border-top-color: white;
border-right-color: white;
border-bottom-color: transparent;
border-left-color: transparent;
}
nav a::after {
content: "";
position: absolute;
top: -2px;
left: -2px;
width: 0;
height: 0;
padding: 0;
background: transparent;
border: 2px transparent solid;
}
nav a:hover::after {
animation: animate2 0.5s linear forwards;
}
@keyframes animate2
{
0% {
width: 0;
height: 0;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: white;
}
50% {
width: 0%;
height: 100%;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: white;
border-left-color: white;
}
100% {
width: 100%;
height: 100%;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: white;
border-left-color: white;
}
【问题讨论】:
标签: html css css-selectors pseudo-element