【发布时间】:2021-09-08 14:18:18
【问题描述】:
为什么导航栏上的动画,那条红线,如果你在nav li a::after 上设置了 100% 的宽度,它会向后工作,而不是从左到右,它应该如何或我想要的?
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;
}
【问题讨论】:
-
因为 div 是向后设置的,字体设置在右侧。我要检查代码以找到解决方案