HTML Quickie: Long String Overflowing Your Div

May 25, 2009 § 6 Comments

Do you have that problem? I do.

EDIT(05/31/2009): Even better solutions:



General CSS solution:

overflow: scroll


The HTML solution:

use <wbr>. (But you have to figure out yourself where to put the tag)

The IE-specific CSS solution:

word-wrap: break-word

PHP solution:

wordwrap(‘your_very_long_string_here’, 15) // Break after 15 characters

Python solution:

import textwrap

textwrap.fill(‘your_very_long_string_here’, 15) # Break after 15 characters



Tagged: , , , ,

§ 6 Responses to HTML Quickie: Long String Overflowing Your Div

  • mike says:

    Python list comprehension isn’t done in memory. Just type “(n for n in xrange(10))” at the console you will see that it produces a generator. On the other hand “[n for n in xrange(10)]” will build a list in memory.

    • mike says:

      oops, somehow committed this to the wrong post. Sorry

    • didip says:

      I always struggle with labels in Python jargon. So, feel free to correct me.

      This, (n for n in xrange(10)), is generator expression.

      and this, [n for n in xrange(10)], is list comprehension. Am I right?

      I’m not arguing back, I just want to get the correct names. =)

  • mike says:

    They are both generators and cases of list comprehension. The term list comprehension isn’t a reference to a data structure, but the abstract idea of a list as a sequence of ordered items.

    When you use the form [n for n in xrange(10)] that is equivalent to passing a generator to the list constructor: list(n for n in xrange(10)).

    List comprehension in python predates generators, so the “[]” form might still be a special case that is processed differently, but conceptually it is the same.

    TIP, you can also do: dict((a,a**2) for a in xrange(9));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading HTML Quickie: Long String Overflowing Your Div at RAPD.


%d bloggers like this: