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

Flawless Prize Fulfilment and Management That Takes Your Marketing Campaigns to the Next Level

In today’s fast-paced and highly competitive marketing environment, even the most creative campaign is only…

1 day ago

Moving company Zeromax in NYC

We are NYC moving firm. Are you planning a flat move? Maybe a distance or…

5 days ago

Mobile testing: An important task for smooth functioning of the device

Mobile devices, unlike desktops and laptops, can not be handled by dozens or hundreds of…

6 days ago

Augmented Reality in Education is Blowing Up the Candles!

Augmented Reality- An immersive experience for the learners! Learning and education aren’t the same as…

1 week ago

Here Are 4 Diamond Studs for You to Gift Your Special Ones

On special days like birthdays and weddings, we all like to celebrate our loved ones…

1 week ago

7 Best Web Application Development Tools

A web application is different from a regular mobile or desktop application as it runs…

1 week ago