Solved

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

Posted on 2003-10-22
11
352 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
ID: 9601538
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
ID: 9601628
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
ID: 9601661
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:roricka
ID: 9601692
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
ID: 9601835
well it worked for me but I didn't try it with a small font. That's probably the problem
0
 
LVL 2

Accepted Solution

by:
HeadAcheMike earned 50 total points
ID: 9602859
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
ID: 9602892
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
ID: 9603317
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
ID: 9603414
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
ID: 9604728
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
ID: 9604741
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 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