DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
Categories: Css3

Truncate String with Ellipsis

Share

Overflow with text is always a big issue in a website, especially in a programmatic environment. Use Ellipsis to truncate string.

We can provide a solution by adding an CSS property overflow: hidden setting to the span, but you can see that the text looked unnaturally cut off.

The way to make text overflow elegant is with ellipses.

The CSS behind creating ellipses is very simple, combining width, wrapping, overflow, and text-overflow:

span{
display:inline-block;
width:200px;
white-space: nowrap;
overflow:hidden ;
text-overflow: ellipsis;
}

Here is total example:

HTML:

<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed cursus pretium metus vitae aliquet. Sed facilisis enim nibh, eget maximus erat dignissim sit amet. In hac habitasse platea dictumst. In nec nunc eu diam pulvinar lacinia nec et arcu. Sed ut enim nunc. Nam lobortis nibh tincidunt nunc scelerisque venenatis</span>

CSS:

span{
display:inline-block;
width:200px;
white-space: nowrap;
overflow:hidden ;
text-overflow: ellipsis;
}

Result will be:

Lorem ipsum dolor sit amet,...

But Firefox doesn’t currently support text-overflow:ellipsis property. There’s one another solution for Firefox provided by Dojo Toolkit: dojox.html.ellipsis.

This resource uses an iFrame shim to create ellipsis.

dojo.require("dojox.html.ellipsis");

After requiring the JavaScript resource, place a dojoxEllipsis node within the page as below:

<span class="dojoxEllpsis">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed cursus pretium metus vitae aliquet. Sed facilisis enim nibh, eget maximus erat dignissim sit amet. In hac habitasse platea dictumst. In nec nunc eu diam pulvinar lacinia nec et arcu. Sed ut enim nunc. Nam lobortis nibh tincidunt nunc scelerisque venenatis</span>
CSS Designer

Recent Posts

Benefits of Manual Therapy for Faster Recovery from Muscle and Joint Pain

Pain in muscles and joints can be a problem in everyday life, whether it involves…

3 days ago

How Digital-First Brands Can Make Offline Marketing Feel Connected

Most modern businesses spend a lot of time thinking about digital touchpoints. Websites, email campaigns,…

6 days ago

X Bets on Video

While TikTok and Instagram battle for users’ attention with short vertical videos, Elon Musk’s social…

2 weeks ago

5 Reasons to use a professional mortgage broker

When you are looking to apply for a mortgage the one thing that most people…

4 weeks ago

Tips – Advanced Blackjack Strategy

Once you've memorized basic blackjack strategy, it's time to delve deeper into the game. Advanced…

1 month ago

The Modern Practice of Yoga: How Balance, Mindfulness, and Lifestyle Design Are Transforming Everyday Wellbeing

Yoga is no longer just a physical practice. Yoga is popular as a lifestyle practice.…

1 month ago