Link to home
Start Free TrialLog in
Avatar of roricka
roricka

asked on

Easy to demonstrate browser bug: too much space on last <br> in a small font span

This simple code fragment exhibits a possible IE 6 bug:

<html>
<head>
</head>
<body>
    <span style="font-size:10">test<br>test<br>test</span>
</body>
</html>

Basically it acts as if the final <br> between the last 2 words "test" were actually two breaks (i.e. <br><br>).
The problem goes away with larger fonts. For font-size:20 there is no problem!!
What is going on here? Anybody know a work around?

roricka
Avatar of DaveSW
DaveSW

Put units after the font-size:10

e.g.

font-size:100%;
font-size:1em;

etc

And that seems to fix it.
and of course, when the CSS is invalid (which when its lacking a unit it is), then its can't be a browser bug - well, it is - it should ignore the font size entirely.
Avatar of roricka

ASKER

Thanks DaveSW, but did you try it?? Because neither using 70% nor .7em  helps me. Both of these show the error (remember -- it only shows up with a smallish font.)

Did you actually TRY your suggestion? I mean, first make sure you are seeing the problem, THEN make the change you suggest. Are you REALLY seeing the problem, and then seeing it go away??

roricka
Avatar of roricka

ASKER

Incidentally, a work around I found myself, but which can't always be used, is to just put ANOTHER <br> at the end. THEN THAT one is the one, apparently, that gets doubled (or whatever) and the previous <br> appears correctly. But what the heck is going on? Why does only the FINAL <br> fail to work properly??

roricka
well it worked for me but I didn't try it with a small font. That's probably the problem
ASKER CERTIFIED SOLUTION
Avatar of HeadAcheMike
HeadAcheMike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i dont know if youd call that a bug or not, more of a "its just that way" situation

i noticed awhile back i encountered a similar problem with the closing </td> tag in a table, i had an image in the cell and putting the </td> on the line below caused it to show an extra gap around the image whereas moving the tag onto the same line that featured the image tag fixed the problem and got rid of the gap.
Avatar of seanpowell
It certainly is a bug as far as I'm concerned - because it obviously shouldn't be happening, and doesn't across all browsers

Consider:
<span style="font-size:10px; border:solid 1px #000000;">test<br>test<br>test<br>test</span>

This gives you an idea of what the browser is doing to the span elements :-(
 I wish I could say it's just IE, but it's not. NS4 (no kidding) and Mozilla get confused as well. Suprisingly, NS6 and 7 and Opera handle it just fine.

So until that happy day arrives when everyone gets it, use this:
<div style="font-size:10px;">test<br>test<br>test<br>test</div>
Avatar of roricka

ASKER

Thanks for all the help.

I knew using <div> would solve the problem, but I specifically wanted a work-around with <span>. So putting the </span> on another line does the trick. Odd!

I've known about the </td> thing (that putting it on a new line can generate a little unwanted vertical whitespace) ever since tracking it down myself a few years ago. But how odd that here is a similar problem, but the fix is just the opposite! (I.e. making sure to put the end-tag on a new line rather than making sure to put the end-tag on the same line.)

Thanks to georgemarian for the illuminating example. Unfortunately it shines with a very dark light!

roricka
Avatar of roricka

ASKER

I've already accepted a solution, but here is ANOTHER variant on this problem that I just discovered (at least I think it must be related.)

In trying to be sure that all font sizes are assigned through styles to prevent the user's browser font setting (i.e. with IE, the View|Text Size|Largest...Smallest etc.) from affecting the appearance of a web page, I discovered the following anomaly. Note the following code:

<html>
<head>
</head>
<body style="margin-top:0px">
    <span style="font-size:10px">test</span>
</body>
</html>

Look at the position of the word "test" with the extreme browser settings (i.e. Largest vs. Smallest, as described above.) Notice how it jumps (again, this positional difference disappears with a font, say, of 20px instead of 10px.) And note, the jump disappears when the </span> is on the next line!! Recal: before the problem was using a <br> tag. Now the problem is having the user change a browser setting. Anybody see a relationship between these two? I am perplexed! (And how come I've never noticed this stuff before? ;-) )

roricka

Avatar of roricka

ASKER

Just discovered ANOTHER wrinkle to the above View|Text Size issue. IF, instead of placing the </span> tag on the next line, you just put a simple space at the end of the word "test" before the </span> tag on the same line, the problem goes away! AND, if instead of a space you use a &nbsp; the problem DOESN'T go away!! Whaaa??

roricka