tags:

views:

150

answers:

6

I'm working on a c# web application and in one sections we show user comments on little boxes. It seems that one person wrote a long string causing the box become bigger.

How can I avoid long words to fit its container size?

For example, if the user writes the following

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

and my box has a shorter width

I should make it fit.

+3  A: 

I like to use

overflow:hidden;

These tend to be outliers and usually are mistakes.

CSS overflow Property

Bertine
I can't cut the comment because of the overflow. For example, if I'd write "Hi,howareyoudoingtoday?" and it's wider than its container, I can't put something like "Hi,howareyoudoin", for example.
Brian Roisentul
How often is that going to happen? Most people will write it as "Hi, how are you doing today?" Which will wrap correctly.You could also try something like this "overflow-y: hidden;" but it isn't supported by many of the older browsers
Bertine
The thing here is that this person wrote areas of expertise separated by "/", but I can't split by that because if someone writes something without it, it will be the same as nothing.
Brian Roisentul
+4  A: 

A common thing to do is check the character count and replace a long string with a shorter one and an elipsis.

aaaaaa...

and then, if youwant, show the full text in the rollover.

<div title="aaaaaa....aaaa">aaaaa...</div>

In code you can do something like

text = allText.SubString(Min(allText.Length, 80))

And combine this with the CSS styling listed in other answers.

No Refunds No Returns
This can work too, I don't know if the owners of the website will accept this solution though. But thank you anyway.
Brian Roisentul
I'm sorry, thinking better I guess this is not a good option for this case, here is why: let's say you write a normal and common text as "Hello World, I'm writing a comment on stackoverflow", so I could make it read "Hello World, I'm writing...", but if I have a single word, without spacings as "my areas of expertise are: software/hardware/sports/animals/economist/lawyer" and cut it on "hardware" because it's too long for the width of the div. The user will only read one line and that's it...no more description on that box, while in the first example the user will see the box full of text.
Brian Roisentul
+5  A: 

Use the css property word-wrap: break-word. That will force long lines to wrap onto the next one.

wsanville
I've seen this and I could make it work on some browsers, but I read not every browser support this property, do you know any other workaround for this to apply to the browsers where this does not work??
Brian Roisentul
A: 

Stackoverflow doesn't seem to care about wrapping words. Perhaps you shouldn't either

dovydasm
-1 for snipe disguised as answer.
David Gladfelter
So if stackoverflow does not do something that means you wouldn't do it anyway? Good luck man.
Brian Roisentul
A: 

For CSS, Here is webmaster example in comments last

http://fun2mobo.awardspace.biz

Works I.e. n Opera and others too check pls

I use overflow:auto and word-wrap:break-word css, overflow aut does display content in all browsers with div having width by style or normally.

Sunny
A: 

You might want to check out the soft hyphen. This is a - in most cases - invisible character that breaks a line.

Peter Kruithof