Scripsit kevgibbo:
I'm currently having a problem where a long URL or a line of text with
no spaces will break the design of a webpage, http://
blog.seoptimise .com/2007/01/how-to-add-delicious-and-digg-blog-
rss.html is an example of this.
Most importantly, don't put URLs into the _content_ proper, only into
attribute values (such as href="...") where long URLs won't hurt.
Roughly speaking, URLs should appear in the content proper only when a page
_discusses URLs_. For example, if you wish to write a page how to refer to
some documents by their URLs in web authoring or in email messages or print
media, you may need some sample URLs, which might be rather long. Then the
prime problem is to _prevent_ browsers from breaking them!
The point is that a long URL usually doesn't hurt in the content unless it
appears in the middle of a text paragraph, where it should not appear, or
you have a rigid page layout, which you should not have.
But it _is_ harmful is a browser breaks a URL after a hyphen "-", as it may
well do. How will the reader know or guess whether the hyphen is part of the
URL or just introduced by hyphenation in word breaking? (Admittedly,
experienced users know that browsers don't hyphenate. But not all users are
experienced. Besides, very experienced users know that browsers may
hyphenate - when a hyphenation hint has been given using the soft hyphen.)
Does anyone know if it's possible to break this text into multiple
lines using CSS?
If you do need to include long URLs into the text of a document, wrap them
inside <nobr>...</nobrmarkup. You may add <wbrtags after points where a
line break is allowed, but then you should use some delimiters or otherwise
make it clear to the user what constitutes the URL. That's the practical
way, and you just have to tolerate people who (correctly) scream
"nonstandar d markup!". CSS could in principle be used for preventing breaks,
since
<nobr>foo</nobr>
effectively corresponds to
<span style="white-space: nowrap">foo</span>
but I don't see much point there. I don't really want to use more
complicated code when nothing else is gained in practice than the risk that
my URLs are broken when CSS is off. So this is a job for HTML, not CSS.
In the CSS 3 drafts, there's the word-wrap property that could be used to
suggest that _any_ line break is allowed in a string, using word-wrap:
break-word. IE supports this. But it's really something to be avoided. It
would violate common sense, readability, and several standards and
recommendations to break a URL _arbitrarily_.
More info:
http://www.cs.tut.fi/~jkorpela/html/nobr.html
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/