Answer the question
In order to leave comments, you need to log in
How to make a line darken if it is longer than the required distance?
Any ideas how to do it? What if the text goes beyond the bounds of the container, it darkened from right to left at the end, some kind of block with a gradient was adjusted, I don’t know. And then I myself will do that when hovering there was an animation that he runs to see the full line.
Like this
Answer the question
In order to leave comments, you need to log in
Compare scrollWidth and clientWidth, if they are different, then the container is full, and then I advise you to add a class in which you will do this "adjustment" :)
<div class="text">Много каких-то букв</div>
.text{
width: 100px;
height: 40px;
position: relative;
overflow: hidden;
white-space: nowrap;
}
.overflowed::after {
content: '';
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 100%;
background: linear-gradient(90deg, transparent, #222);
pointer-events: none;
}
const el = document.querySelector('.text');
if (el.scrollWidth !== el.clientWidth) {
el.classList.add('overflowed')
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question