1

I was asked "How come in newer browsers, newlines are treated as newlines"... a very odd question as I would expect, based on the question, that the seen behavior was expected.

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<html>
<head>

<title>
</title>
</head>
<body>
<p title="test 
test 
test">test a b c</p>
</body>
</html>

However, if you look into the past examples., newlines were treated as spaces., and not newlines., Why does the browser renders a newline as space?

so; using CSS, how do you get the newer browsers to treat the new lines as spaces?

If you were to create the above in notepad and save it as html., the tooltip would show as

test
test
test

and not the expected

test test test
Community
  • 1
  • 1
zxed
  • 11
  • 1
  • Your `meta` should be inside of the `` tag. This doesn't render like you said in Firefox. What browser are you seeing this in? Also, what "tooltip" are you referring to? Also, you need a `DOCTYPE`. – matthewpavkov Feb 16 '11 at 07:41
  • This is definitely strange. I thought a basic fact of HTML is that whitespace is whitespace, whether it be a space, tab, newline etc - all of it acts like a space – Ken Wayne VanderLinde Feb 16 '11 at 07:44
  • I think above will show "test a b c" not test test test – Ankush Roy Feb 16 '11 at 07:45
  • @matthewpavkov - zxed is referring to the "Tooltip", which is the text in the floating box that is shown when you hover your mouse pointer over the element. – Kevin Fegan Jan 06 '14 at 10:15
  • @AnkushRoy - The text rendered on the page will be "test a b c", but the "Tooltip" (the text in the floating box that is shown when you hover your mouse pointer over the element) will show "test\ntest\ntest". – Kevin Fegan Jan 06 '14 at 10:17

1 Answers1

3

This applies only to tooltips.

Webkit browsers (Chrome, Safari) do it.
Gecko browsers (FF, Flock...) don't.
IE 7+ does (don't know before).

It gives the author the possibility to format a little bit long tooltips so that they don't span across the whole width of the page. Please note that most browsers (including Gecko based browsers) nevertheless also feature automatic boxing algorithms to keep the tooltips readable. It's just that the ones supporting this feature also give more controls to the author).

Since it applies only to tooltips, no CSS attribute can affect this behaviour.

Alain Pannetier
  • 9,315
  • 3
  • 41
  • 46