6

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..."

Prasad
  • 519
  • 9
  • 22
  • Look here http://davidwalsh.name/css-ellipsis – singe3 Aug 13 '14 at 09:11
  • [**Text-overflow:ellipsis @ MDN**](https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow) – Paulie_D Aug 13 '14 at 09:11
  • Google gets a lot more helpful when you know the name of what you're trying to do.. these are called 'ellipsis': http://css-tricks.com/snippets/css/truncate-string-with-ellipsis/ – Flynn1179 Aug 13 '14 at 09:12
  • [my solution here](http://stackoverflow.com/a/18458345/703717) may also help you as it shows some methods for a multi-line ellipsis – Danield Aug 13 '14 at 09:48

2 Answers2

8

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.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
0

Add CSS to the div.

 div
    {
    text-overflow:ellipsis;
    }

Hope it help

Khaleel
  • 1,212
  • 2
  • 16
  • 34