html - CSS 动画留下杂散像素
问题描述
我试图在我的导航栏链接上实现一个简单的“悬停下划线”动画。然而,动画完成后会留下杂散像素,如下面的 GIF 所示。
奇怪的是,如果我将光标悬停在具有相同动画的两个链接之间,它就不会发生。仅当我将鼠标悬停在链接上然后将光标移动到其他位置时才会发生这种情况。
我已经实现了导航栏如下: -
<div class="nav-bar-flex">
<a href="#">Home</a>
<a href="#">Company</a>
<a href="#">Careers</a>
</div>
CSS:
.nav-bar-flex a {
display: inline-block;
color: white;
text-decoration: none;
font-size: 1rem;
font-weight: 400;
letter-spacing: -0.055rem;
}
.nav-bar-flex > a::after {
content: "";
display: block;
width: 0%;
border-bottom: 2px var(--secondary-orange) solid;
margin-top: 0.3rem;
transition: width 300ms;
}
.nav-bar-flex > a:hover::after {
width: 100%;
transition: width 300ms;
}
解决方案
为 after 及其过渡添加不透明度
.nav-bar-flex a {
display: inline-block;
color: white;
text-decoration: none;
font-size: 1rem;
font-weight: 400;
letter-spacing: -0.055rem;
}
.nav-bar-flex > a::after {
content: "";
display: block;
width: 0%;
opacity: 0;
border-bottom: 2px var(--secondary-orange) solid;
margin-top: 0.3rem;
transition: width 300ms, opacity 300ms;
}
.nav-bar-flex > a:hover::after {
width: 100%;
opacity: 1;
transition: width 300ms, opacity 300ms;
}
推荐阅读
- php - PHP - 根据文件名模式查找最新文件
- python - 带有嵌套在python中的curl请求
- salt-stack - 盐代理奴才概念
- javascript - 在 ES6 之前的代码中使用“let”和“const”可以吗?
- sql - 根据数据将标识值添加到现有列
- javascript - 在同一页面上将滚动方向从垂直更改为水平
- asp.net-mvc-4 - 找不到方法:'System.Collections.Generic.List`1
- java - 找不到符号枚举
- java - 使用 Swagger 注解显示自定义 HashMap 键
- ios - 通过自定义按钮删除 UICollectionViewCell