CSS: Value for display to avaid line breaking ?

M

Matthias Pospiech

I define a class url
..url
{
display: ??;
color: #606060;
}

which is used as

<li>
<a href="http://www.tug.org/interest.html">TeX Resources on the Web</a>
<span class="url">http://www.tug.org/interest.html</span></li>

now I want the span to be a block, ie. to break in to the next line if the
url does not fit into the current one.

What kind of value for display is the correct on in that case ?
I tried "block", but that puts it always in the next line.

Matthias
 
T

Toby Inkster

Matthias said:
now I want the span to be a block, ie. to break in to the next line if the
url does not fit into the current one.

You are misunderstanding what a block is.

You probably want:

white-space: nowrap;
 
J

Jukka K. Korpela

Matthias Pospiech said:
I define a class url
.url
{
display: ??;
color: #606060;
}

You should always specify background whenever you specify color.
What if the user's style sheet contains
* { background: #606060; color: black; }
?
<li>
<a href="http://www.tug.org/interest.html">TeX Resources on the
Web</a> <span
class="url">http://www.tug.org/interest.html</span></li>

now I want the span to be a block, ie. to break in to the next line if
the url does not fit into the current one.

That's not what "block" means. A block unconditionally begins on a new line
(unless you do something else explicitly).
What kind of value for display is the correct on in that case ?

The value inline, which is the default value, so it need not be specified.

Toby's suggestion of using white-space: nowrap might be what you are after.
Contrary to its name - CSS property names are often misleading - it
prevents line breaks inside the content, except for explicitly created
breaks (e.g., <br>). Thus it may prevent a browser from splitting after "/"
for example. Whether this is a good thing to do is a different issue.

Normally URLs should appear as attribute values, not in document content
proper. Have you ever listened to a speech browser reading URLs? It doesn't
actually improve the experience. It's sufficient to have the link there.

If you wish to include a URL for _printed_ copies, then again this might
not be a good idea. The URL of the page itself is usually sufficient and
can be included into the printed copy by the user if desired, and many
browsers can automatically generate a list of URLs appearing in links.

But if you do include a URL into document content proper, I would recommend
using quotation marks or the characters "<" and ">" as delimiters and
encourage (rather than discourage) browsers into splitting a URL across
lines, as described in more detail at
http://www.cs.tut.fi/~jkorpela/html/nobr.html#url
 
T

Toby Inkster

Matthias said:
Maybe - any information ?

A block is a chunk of text that starts on a new line and ends with a line
break.

Examples of blocks are:

- a paragraph
- a list item (like this)
- a heading

So a block begins and ends with a line break, but that's not to say that
it can't have line breaks in between. A reasonably long paragraph, such as
this one, will extend onto several lines, but is considered as a block.
It work, though an URL has no white space...

As Jukka said, CSS properties are often oddly named.

Consider there is a "background-color" but no "foreground-color". To make
things bold you use "FONT-weight", but to underline them you use
"TEXT-decoration".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top