Solved

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

Posted on 2003-10-22
11
322 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:roricka
  • 5
  • 2
  • 2
  • +2
11 Comments
 

Expert Comment

by:DaveSW
Comment Utility
Put units after the font-size:10

e.g.

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

etc

And that seems to fix it.
0
 
LVL 17

Expert Comment

by:dorward
Comment Utility
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.
0
 

Author Comment

by:roricka
Comment Utility
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
0
 

Author Comment

by:roricka
Comment Utility
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
0
 

Expert Comment

by:DaveSW
Comment Utility
well it worked for me but I didn't try it with a small font. That's probably the problem
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 2

Accepted Solution

by:
HeadAcheMike earned 50 total points
Comment Utility
putting the closing span tag on a new line fixed it when i tried it:

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

Expert Comment

by:HeadAcheMike
Comment Utility
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.
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
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>
0
 

Author Comment

by:roricka
Comment Utility
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
0
 

Author Comment

by:roricka
Comment Utility
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

0
 

Author Comment

by:roricka
Comment Utility
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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, html5 UI 1 47
css to place image in corner of html table cell. 5 40
CSS grid style change 2 13
Change month dropdown 5 15
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now