Add text ellipsis without needing a fixed width.

by Bryan Braun

HTML

<div class="ellipsis">
  <span>Very very long text, long long long text, long text, for this line.</span>
</div>

CSS

.ellipsis {
    position: relative;
}

.ellipsis:before {
    content: '&nbsp;';
    visibility: hidden;
}

.ellipsis span {
    position: absolute;
    left: 0;
    right: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}