HTML / CSS Ellipsis (...) Not Working
Asked Answered
B

2

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>
Besmirch answered 25/5, 2012 at 23:30 Comment(6)
Are you sure you're using a CSS3 compliant browser?Tartuffe
Check out this answer if you're on FF: #4927757Lexical
Looks fine to me jsfiddle.net/ZBQnLHemoglobin
Working fine in latest versions of Chrome, FF, and IE9Afterdeck
This shouldn't even need a CSS3 compatible browser - even IE6 renders white-space:nowrap and text-overflow:ellipsis correctly.Anhanhalt
Managed to fix it by styling the paragraph rather than the whole div. Cheers :)Besmirch
L
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.

Lexical answered 25/5, 2012 at 23:41 Comment(2)
Seems to work fine on jsfiddle.net - I have the styling in a separate stylesheet.Besmirch
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.Lexical
M
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;
}
Malay answered 15/4, 2015 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.