Forum Moderators: not2easy

Message Too Old, No Replies

Font Size Inheritance Issues

Why do some html elements not inherit my font sizes?

         

Craig_F

12:45 pm on Jun 4, 2003 (gmt 0)

10+ Year Member



here's a sample:

<style type="text/css">
<!--
body {font-family: verdana,sans-serif;
font-size: 14px;
color:#333; }
-->
</style>
</head>

<body>
<p>this is the right font.</p>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>this should be the same font but it is not. seems to pick up the family, but not the size.</td>
</tr>
</table>
</body>
</html>

What's the deal here? Seems like I'll have to set another style, but that seems redundant.

pageoneresults

1:15 pm on Jun 4, 2003 (gmt 0)

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



There appears to be some problems with the cascade with certain browsers and tables. You could do this...

<style type="text/css">
<!--
body, td {font-family: verdana,sans-serif;
font-size: 14px;
color:#333; }
-->
</style>

Receptional Andy

1:27 pm on Jun 4, 2003 (gmt 0)



I was waiting for a CSS-guru type to answer this one :)

>>certain browsers

I tried this in IE, Mozilla and Opera and they all showed the incorrect(?) font size. Shall I put this in the 'browsers don't interpret CSS correctly' file? It's the kind of thing that really tripped me up when learning CSS...

pageoneresults

1:41 pm on Jun 4, 2003 (gmt 0)

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



I was waiting for a CSS-guru type to answer this one :)

I'm waiting too! I picked up this tidbit of information here a while back. At the time, Opera was not displaying h tags based on my stylesheet rules. They were showing as times when they should have been verdana.

To avoid any future problems with the cascade, I now do this...

body, div, form, h1, h2, h3, h4, h5, h6, input, li, ol, p, select, td, textarea, tr, ul
{font-family:verdana, arial, helvetica, sans-serif;}

That way I don't have to worry about any cascade issues. I make sure that I've listed all my used block level elements in that one general rule.

According to the spec, you should be able to specify the font for the entire document using the body class. But, as we know, things don't always work according to the specification. ;)

Receptional Andy

1:44 pm on Jun 4, 2003 (gmt 0)



Yeah, I do the same thing instead of doing just body {} styles. Did you miss 'a' from your list or do you not include it?

pageoneresults

1:47 pm on Jun 4, 2003 (gmt 0)

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



Did you miss 'a' from your list or do you not include it?

Never thought to include it. I know of two elements where the cascade has issues; h tags and tables. I haven't seen any issues with a elements but I might as well add that to the list.

I'm hoping one of the CSS Gurus will jump in here and give us specifics on which elements have problems with the cascade.

Craig_F

2:08 pm on Jun 4, 2003 (gmt 0)

10+ Year Member



thanks a lot for this. I figured it was a cascade issue, but didn't want to add the extra styles if I didn't need to. off to add the styles in...

Nick_W

3:01 pm on Jun 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> figured it was a cascade issue,

Actually it's an inheritance issue. I'm afraid I'm just not the human dictionary type so I can't remember which browsers do inherit correctly from the body tag and which dont.

I know this though: For maximum backward compatability I always style table elements (td,th,caption etc) explicitly and I never expect anything to inherit from the body tag. It's just one of those tricky areas ;)

Nick

ShawnR

3:02 pm on Jun 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not a CSS guru either, I'm afraid, but here is my 2 cents worth:

font-size should inherit (see section 5.2.6 of [w3.org...] ). However, the spec says:
"Note that an application may reinterpret an explicit size, depending on the context".

So for example <h1> would inherit the colour, but doesn't inherit the size. It certainly would not be sensible for a heading to be the same size as the body text, although you could argue that it would have been sensible for the spec to be written such that headings are a proportion of the font-size of what they inherit from. Unfortunately it is not writtent that way, and instead gives quite a bit of freedom to the browser developer.

It seems that td's are similar to headings in this regard.

So, with:

body, div, form, h1, h2, h3, h4, h5, h6, input, li, ol, p, select, td, textarea, tr, ul
{font-family:verdana, arial, helvetica, sans-serif;}
Its generally not the font-family that is the problem (except on old yukky browsers like NN 4.7). Its the font-size.

Shawn

Longhaired Genius

3:04 pm on Jun 4, 2003 (gmt 0)

10+ Year Member



...didn't want to add the extra styles if I didn't need to.

Too true. Luckily, you don't need to.

Just style your table like this: table {font-size: 1em} and all will be well.

drbrain

3:20 pm on Jun 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Set your doctype properly, and all will be well.

Receptional Andy

3:43 pm on Jun 4, 2003 (gmt 0)



Set your doctype properly, and all will be well.

Got it in one drbrain :)
Above code works fine in 4.01 strict.

[rhetorical question] Why am I such a sucker for not setting a doctype when i'm testing things? [/rhetorical question]

pageoneresults

6:48 pm on Jun 4, 2003 (gmt 0)

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



Inheritance/Cascade, I just can't seem to get those two correct. Sorry for the confusion.

Its generally not the font-family that is the problem (except on old yukky browsers like NN 4.7). Its the font-size.

Shawn, in the scenario I was working with, Opera was not displaying h tags in the specified verdana font. As soon as I added that general rule in my style sheets, the problem was solved.

SuzyUK

7:42 pm on Jun 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have to agree here it's usually only tables that have a problem in some browsers but it seems like it's an Opera 7 bug :(

it's not inheriting the font family only noticed it today having started to use O7.11 this week, never noticed it before..

Suzy

pageoneresults

7:43 pm on Jun 4, 2003 (gmt 0)

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



Have to agree here it's usually only tables that have a problem in some browsers but it seems like it's an Opera 7 bug :(

I caught onto it when I first downloaded 6.0 way back when.

SuzyUK

8:38 pm on Jun 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can't say I see it in Opera 6.. (same page, same default settings)

but another thing to remember anyhow..

* {font-family: verdana, helvetica, arial, sans-serif;}

this would workaround all elements would it not?

*thoughts* maybe not a "bug" may just be Operas interpretation in that if headings should not inherit size, because that's sensible, than perhaps they're putting font-family in the same category? a lot of sites have their headings in a different font...

Thinking out loud
Suzy

ShawnR

12:24 pm on Jun 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shawn, in the scenario I was working with, Opera was not displaying h tags in the specified verdana font

OK, thanks. I guess I never saw that for some reason.

Just to reiterate what Suzy wrote, in some circles there is a rule that print media uses a san-serif font for headings and serif'ed font for the body text. This is because it is faster to read a printed serif font, and you want the ausdience to read the body fast but to linger on the heading. For online media the rule is reversed because it is fater to read a san-serif font on screen.

Shawn