Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Large text with dotted end

Tags:

html

css

I want to display text inside a fixed size div if the size of text is large than more text should be indicated with dots.

example

if number of text can be displayed inside div is 10 then

text "Australia" should be displayed like "Australia" text "United States Of America" should be displayed like "United Sta..."

like image 636
Prasad Avatar asked Aug 13 '14 09:08

Prasad


People also ask

How do you get the dots at the end of the text when its overflow?

Quite easy thing to do: just add / remove class with text-overflow:ellipsis.

How can I show dots in a span with hidden overflow?

To add an ellipsis in the HTML <span> element having the CSS overflow property set to “hidden”, you need to add the text-overflow property. Use its “ellipsis” value, which will add dots at the end of the content within the <span>.

How do I put three dots on a text too long CSS?

Text overflow is a way to limit text that exceeds the width of the element and to insert an ellipsis (three dots “…”). text-overflow: ( clip | ellipsis | <_string_> ); When showing text-overflow: ellipsis in my lectures, I always get two reactions.


1 Answers

This is the CSS property you're looking for:

text-overflow: ellipsis;

For example:

<div style="width: 5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
    United States of America
</div>

Will display

United St...

The text must be in one line (hence the white-space: nowrap), and overflow a box where the overflow is hidden (hence the overflow: hidden). Fiddle available here.

like image 198
Robby Cornelissen Avatar answered Oct 14 '22 04:10

Robby Cornelissen