Cut off text if its too big for a table? (Resize table?)


#1

I made a nice (imo), custom table for my posts while following a simple
blog in Rails tutorial. I was wondering tho if I can set a maximum width
for a table row/cell and have it cut off text if its too long to fit, so
it just shows a preview of the blog post. Also, is it possible for the
table to size and get bigger with the resizing of a browser window? I
know that this is mostly an HTML problem, so I’m sorry if this is the
wrong place.


#2

There should be a way to just limit the number of words displayed from
a certain field. Do it that way and then you’ll have some consistency.
I can’t think at the moment, but I would think there is a way to limit
the number of words to just a certain limit relatively easily in Ruby/
Rails.


#3

Hi Tim,

On Fri, 2009-03-06 at 18:48 +0100, Tim M. wrote:

I made a nice (imo), custom table for my posts while following a simple
blog in Rails tutorial. I was wondering tho if I can set a maximum width
for a table row/cell and have it cut off text if its too long to fit, so
it just shows a preview of the blog post. Also, is it possible for the
table to size and get bigger with the resizing of a browser window? I
know that this is mostly an HTML problem, so I’m sorry if this is the
wrong place.

I can think of a couple of ways to approach this.

CSS overflow - not sure if this works with table elements, but you can
set the overflow attribute in a CSS rule to simply clip content to the
element size, make the element scroll, or a couple of other choices.

Helper methods - either a view helper, or a method in your model, can
trim the string prior to display; assuming you know the size you want to
trim it to.

I prefer the CSS approach because it’s simpler. It’ll automatically
take care of the resizing issue. But, like I said, I’m not sure if it’s
supported with table elements. Make a test and let us know.

HTH,
Bill


#4

Tim M. wrote:

I made a nice (imo), custom table for my posts while following a simple
blog in Rails tutorial. I was wondering tho if I can set a maximum width
for a table row/cell and have it cut off text if its too long to fit, so
it just shows a preview of the blog post. Also, is it possible for the
table to size and get bigger with the resizing of a browser window? I
know that this is mostly an HTML problem, so I’m sorry if this is the
wrong place.

i agree with the previous post that you should just limit your word
count so it would just kill anything over the limit and replace it with
a link “…” that goes to full text…

that seems to be the bog standard way to do it.