Forum Moderators: open

Message Too Old, No Replies

HTML Strict and line spacing in TD on Firefox and Safari (not IE)

         

ajsefk

1:03 am on Feb 3, 2006 (gmt 0)

10+ Year Member



I have a problem that only reproduces in STRICT mode (Firefox and Safari, but not IE).

Here's a much-reduced testcase (replace "LOTS OF TEXT" with lots of text). The border and special font sizes are to exaggerate the problem.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<body style="font-size:2em">
<div style="border:1px solid"><span style="font-size:0.5em">Lorem ipsum dolor ..LOTS OF TEXT...Ut quis ante. </span></div>
</body>
</html>

You'll get the idea if you just render this on IE and Firefox, and note the difference. The spacing is unnecessarily large on Firefox. On IE it looks right. Also, if rendered using Transitional DOCTYPE, it looks right (i.e. tight spacing).

The problem as I said is the line spacing. What seems to be happening is that the DIV is using the large font size, and using it for line spacing, even though the only thing inside of it is a SPAN with a smaller font size.

I realize I could just move the font-size from the SPAN out to the DIV, and I would get the desired behavior.

But I cannot do this because the <div> and </div> are generated by one system, and the content is dynamically created (like little portlets). If the portlet wants to show small text, like in this case, this large line spacing is imposed on it.

How can I avoid the large line spacing on the SPAN inside the DIV?

I hope this belongs here and not the CSS forum.

tedster

1:49 am on Feb 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think that the difference is that span is an inline element and div is a block-level element. There are different rendering rules for line-height in the two cases.

I've struggled with reading the W3C's visual formatting model [w3.org] to get a theoretical handle on this and my eyes are going crossed! But for practical purposes, note that if you use <p> which is block-level, instead of <span>, then the difference between the two browsers vanishes.

ajsefk

5:35 pm on Feb 6, 2006 (gmt 0)

10+ Year Member



Thanks, tedster. I tried replacing the <span> with <p>, and although you're correct that the two browsers render identically, this is not an option for me.

I need the elements to be inline, because there may be a series of them that must appear on the same line.

pageoneresults

5:41 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How can I avoid the large line spacing on the SPAN inside the DIV?

Wouldn't you use specificity in the style sheet and make sure that span is included in the style? I think I know what your talking about and I just ran into this recently. It was because I use specificity in my style sheet and I had to include the span.

My understanding is that applying font size to the body element does not cascade down through to all elements. :(

I hope this belongs here and not the CSS forum.

I think it is going to end up at the CSS forum. ;)