Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I only display part of a string using css

I want to be able to display a string of characters up to 10 characters. If the string goes over 10 characters, I'd like to append '...' to the end.

For example, if I have the string:

'helloworldmynameisryan'

I want it to be displayed like so:

'helloworld...'

I'm just displaying my string in a div like this:

<div>DisplayMessage</div>

Is there a class that I could create that would only apply if the string were over 10 char?

like image 411
DannyD Avatar asked Mar 14 '13 04:03

DannyD


1 Answers

Firefox does in fact now support this, you just need to ensure that whatever you are trying to 'truncate' has block level formatting and a width - which could be the parent.

.ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display:block;
    width : 100px; /* this could be defined on any parent */
}
like image 144
Carrie Morrison Avatar answered Oct 05 '22 19:10

Carrie Morrison