当按钮禁用时,仅动画底部边框宽度为0。
CSS代码示例:
button {
position: relative;
border: none;
background-color: transparent;
padding: 10px 20px;
font-size: 16px;
color: #333;
cursor: pointer;
}
button:disabled::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 2px;
background-color: #333;
animation-name: border-animation;
animation-duration: 1s;
}
@keyframes border-animation {
to {
width: 0;
}
}
以上代码中,在按钮禁用时使用伪元素 ::after
添加一个底部边框,并为其添加一个宽度动画。当动画完成时,底部边框宽度将变为0。