html - 向后导航动画
问题描述
为什么导航栏上的动画,那条红线,如果你设置 100% 宽度nav li a::after
向后工作,而不是从左到右,它应该如何或我想要如何?
HTML
<nav>
<ul>
<li><a href="index.php">Domů</a></li>
<li><a href="switcher.php">Fun Switcher</a></li>
<li><a href="#">Radio</a></li>
<li><a href="#">Fotky</a></li>
<li><a href="#">Games</a></li>
<li><a href="#">Chat</a></li>
</ul>
</nav>
CSS
nav {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
grid-area: nav;
font-weight: bold;
}
nav ul {
list-style: none;
margin: 0;
display: flex;
justify-content:flex-start;
align-items: center;
padding: 1em 0;
}
nav li a {
text-decoration: none;
color: #000000;
padding-left: 3em;
position: relative;
transition: all ease-in-out 250ms;
}
nav li a::after {
content:'';
position: absolute;
display: block;
height: 0.4em;
background-color: red;
bottom: -1em;
/* width: 100%; look for whole line */
transition: all ease-in-out 250ms;
}
nav li a:hover::after {
width: 60%;
}
nav li a:hover{
color: red;
}
解决方案
您想更改多项内容,因为某些 css 属性不适合您的 html 类...
nav {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background: linear-gradient(#ffffff, #f5f5f5);
grid-area: nav;
font-weight: bold;
}
nav ul {
list-style: none;
margin: 0;
display: block;
}
nav li {
padding: 13px 20px;
display: inline-block;
}
nav li a {
text-decoration: none;
color: #000000;
position: relative;
transition: all ease-in-out 250ms;
}
nav li a::after {
content:'';
position: absolute;
display: block;
height: 0.4em;
background-color: red;
bottom: -1em;
/* width: 100%; look for whole line */
transition: all ease-in-out 350ms;
left: 0;
width:0;
}
nav li a:hover::after {
width: 100%;
}
nav li a:hover{
color: red;
}
<nav>
<ul>
<li><a href="index.php">Domů</a></li>
<li><a href="switcher.php">Fun Switcher</a></li>
<li><a href="#">Radio</a></li>
<li><a href="#">Fotky</a></li>
<li><a href="#">Games</a></li>
<li><a href="#">Chat</a></li>
</ul>
</nav>
推荐阅读
- javascript - NavigationPreloadManager 中使用的标头值是什么?
- powershell - PowerShell 从本周五开始获得 12 个月的周五
- react-native - 为什么设置 remoteDescription 时 RTCPeerConnection 会抛出只读错误?
- python-3.x - 集成方法,我该怎么办?
- javascript - 当我尝试绕轴和中心旋转时,对象在屏幕外平移
- c++ - void __cdecl QtFontFamily::ensurePopulated(void): "??????????" 中 Qt:ASSERT 失败的一些问题 使用 QWebEngineView 时
- c# - “异常成功发送到服务器”事件
- spring-boot - SpringBoot 与 mybatis mapper 多数据库
- amazon-web-services - 我可以使用 terraform 数据创建 {instanceid: valueOfNameTag} 的地图吗?
- python - 有没有办法使用 Google Sheets API 来逃避潜在的单元格引用?