5

I'm attempting to get ellipsis working on my site. This is the following HTML / CSS code and it doesn't appear to be working.

CSS:

.oneline {
text-overflow:ellipsis;
white-space: nowrap;
width: 50px;
overflow: hidden;
}

HTML:

<div class="oneline">Testing 123 Testing 456 Testing 789</div>
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
Storm3y
  • 121
  • 1
  • 4
  • 12

2 Answers2

11

Based on the initial post, we're all assuming the obvious, but just in case ... ;)

<style type="text/css">
    .oneline {
        text-overflow : ellipsis;
        white-space   : nowrap;
        width         : 50px;
        overflow      : hidden;
    }
</style>
<div class="oneline">Testing 123 Testing 456 Testing 789</div>

http://jsfiddle.net/NawcT/

EDIT: Solution was to style the paragraph vs the div.

Community
  • 1
  • 1
AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • Seems to work fine on jsfiddle.net - I have the styling in a separate stylesheet. – Storm3y May 26 '12 at 00:06
  • Are you using multiple stylesheets? Maybe you have a resetter which is clobbering your `text-overflow` or `overflow` rules. You can try adding `!important` after the rule assignments to test that theory. – AlienWebguy May 26 '12 at 00:11
0

Assigning position:absolute to the element to be truncated will probably have less undesired side-effects that float:left.

This worked for me:

div {
  position: absolute;
  width: 70px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
Oliver Schafeld
  • 17,358
  • 2
  • 15
  • 13