3

I want to have a two-column list of items where the right column has a fixed width, and the left column is determined by the window size, with its text truncated:

+----------------------+-----------+
|Variable width text...|Fixed width|
+----------------------+-----------+

All of the examples I've found on how to do truncated text in HTML/CSS use a fixed width for the truncated text, so they don't work for my variable-width case. I usually end up with the left text not being truncated, causing the element to be wider than it should be.

I'd include sample code, but I've tried so many different things I don't know which wrong approach to post :)

This is for a WebView in a desktop application, so I only need it to work with the latest WebKit.

3
  • Truncated as in word wrap or really just gone? Commented Aug 10, 2012 at 16:18
  • And if you want the three dots, google "jquery ellipsis" Commented Aug 10, 2012 at 16:26
  • Yes, I'm going for the ellipsis. Commented Aug 11, 2012 at 4:18

1 Answer 1

4

If you really want to text to be truncated you could do something like: http://jsfiddle.net/fju9q/2/

Which uses 2 divs. The right div is floated and the left div uses overflow: hidden and white-space: nowrap; to make sure the text is truncated.

Sign up to request clarification or add additional context in comments.

2 Comments

That gets me most of the way there. My next problem is that this is inside a table, and the td seems to be calculating its width based on the pre-truncated text - jsfiddle.net/Q3AbF
Aha, I've got it now. I just needed table-layout: fixed. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.