My goal is to hover over truncated text and reveal the full length of the dynamic text. However, I am struggling with removing extra space at the end of shorter text when hovered and displaying all the text for longer ones.
I have a solution that almost works, but I need help refining it. You can view my Codepen here.
Below is the HTML:
<ul>
<li>
<a class="link" href="#">Example of really long blog title goes here</a>
</li>
<li>
<a class="link" href="#">Example of really long blog title goes here - this is a longer text</a>
</li>
<li>
<a class="link" href="#">Example of really long blog title goes here - this is an even longer length to test</a>
</li>
</ul>
And the CSS:
ul {
width:200px;
overflow:hidden;
background:#f2f2f2;
}
.link {
display:block;
white-space: nowrap;
width:auto;
transform: translateX(0%);
transition: 4s ease-in-out;
}
.link:hover {
color:red;
transform: translateX(-100%);
}
Any advice on how to improve my implementation would be greatly appreciated!