Is it possible to use CSS to truncate text based on the current screen size or media queries? For example, consider this paragraph:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porta tortor
vitae nisl tincidunt varius. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Ut vel ullamcorper tortor...
I am looking for a way to truncate text dynamically based on the device being used to view the page. Is there a CSS solution that can achieve this?
.truncate-ellipsis {
display: table;
table-layout: fixed;
width: 100%;
white-space: nowrap;
}
.truncate-ellipsis > * {
display: table-cell;
overflow: hidden;
text-overflow: ellipsis;
}
<div class="truncate-ellipsis">
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porta tortor vitae nisl tincidunt varius. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vel ullamcorper tortor...
</span>
</div>