I can’t figure out what properties should be added to the elements to remove the jumping effect (I want to fix it). Maybe you should use grid? All parameters should remain as they are (the font cannot be changed)
.nav-list {
padding: 0;
margin: 0;
display: flex;
list-style: none;
}
.navlist__item:first-child > .nav-list__link {
padding-left: 0;
}
.nav-list__item:last-child > .nav-list__link {
padding-right: 0;
}
.nav-list__link {
display: inline-block;
color: inherit;
font-size: 17px;
text-decoration: none;
padding: 15px 19px;
}
.nav-list__link:focus {
color: #8428f8;
font-weight: 800;
font-size: 16px;
transition: all 0.3s;
}
<nav class="nav">
<ul class="nav-list">
<li class="nav-list__item">
<a class="nav-list__link" href="#about">About me</a>
</li>
<li class="nav-list__item">
<a class="nav-list__link" href="#experience">Experience</a>
</li>
<li class="nav-list__item">
<a class="nav-list__link" href="#skills">Skills</a>
</li>
<li class="nav-list__item">
<a class="nav-list__link" href="#projects">Projects</a>
</li>
<li class="nav-list__item">
<a class="nav-list__link" href="#cv">CV</a>
</li>
</ul>
</nav>
3
Answers
There seems to be both a vertical and horizontal "jump" taking place.
For the vertical jump, I think you’ll need
align-items: baseline
on the flex container.For the horizontal jump, the root cause seems to be the
font-weight
transition. Unfortunately, without variable fonts, a truly smooth animation is impossible (and the original question asked to not change the font). However, a similar (not identical) effect can be achieved usingtext-shadow
. The original idea for this workaround came from this answer.Both solutions listed above are demonstrated in the snippet below.
To remove the jumping effect when the link is clicked, you can add outline: none; to the .nav-list__link:focus selector. If not, change or remove transition: all 0.3s;
In order to prevent this behavior you can use
transform
property withscale
. You can read more on MDN.Snippet: