I’m creating a text using CSS. The idea is that the text increases in size when hovered on, like the apple taskbar. I am attaching my code below; although the text is expanding, there seems to be a problem with the positions of the text.It is effecting the position of other elements in the navbar. I tried different position types to solve this, but it seems not working. It will be helpful if anyone can find the error
.nav-list {
position: relative;
display: inline-flex;
top: 2.2rem;
}
.nav-list li {
position: relative;
left: 215%;
padding: 0 20px 0 20px;
}
.nav-list a {
font-weight: 500;
}
.nav-list>li>a::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 4px;
width: 0;
left: 0;
bottom: -10px;
}
.nav-list>li:hover>a::after {
width: 100%;
}
.nav-list>li>a {
font-size: 16px;
transition: font-size 0.5s ease;
}
.nav-list>li:hover>a {
font-size: 20px;
transition: font-size 0.5s ease;
}
<div class="watashiva">
<ul class="nav-list">
<li><a href="">MEN</a></li>
<li><a href="">Test</a></li>
<li><a href="">WOMEN</a></li>
</ul>
</div>
2
Answers
Just set a width on the
li
elements. This will prevent them from expanding and shifting the other elements.If you want to text expand when hovering it, just use CSS
transform: scale(x)
(🔗). It makes the remaining text not affected.Just change
to
Full code: