I have a container which has some text. As the size of the container is reduced, the text must be truncated. But I want the truncation to only happen till a specific minimum width of the container beyond which the text should be hidden. Is it possible to achieve this using only CSS?
<div class="container">
This is some text
</div>
.container {
width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
2
Answers
What you require is a container query which requires that the text have a wrapper such as a
p
tag.Codepen Demo
Here is an example using
clamp()
where the item is hidden below50px
of width.Resize of the container to test: