views:

26

answers:

3

Hey,

Say if I set the font-family for the page body to font1, font2, font3 and then I set the h1 tag's font family to font4, font5. If font 4 and 5 weren't installed, would the browser try font 1,2 and 3 before it used the browsers default font?

+2  A: 

nope. it will default to the browser default.

Moin Zaman
+5  A: 

No, because when you specify font-family, the font stack doesn't get inherited from the parent element and then added to. You're giving it a brand new font stack of its own, separate from its parent element's.

If you want the browser to use the first three fonts for <h1>, you need to specify that:

body { font-family: font1, font2, font3; }
h1 { font-family: font4, font5, font1, font2, font3; }

Tedious, but that's how CSS font-family works :)

BoltClock
Thanks. Shame it works like that, would have saved a bit of hassle.
Ryan
+4  A: 

Short Answer: No

Good question. The feature you are talking about is known as inheritance. Essentially, will a child element inherit a parent's font-family if its own specified font-family is not installed on the user's computer.

I couldn't find any explicit documentation although this specification could be taken to mean that no inheritance will occur in this case. Therefore, to make sure, I tested out the latest stable build of Firefox with the following:

<body>
    <p>Hello</p>
</body>

body {font-family: Arial;}
p {font-family: Quill;}

I don't have Quill installed but I do have Arial. However, despite this fact, the p element is rendered in the default serif font, not in Arial.

Since there is at least one major browser that functions in this way, in order to ensure consistency, you should always use this instead:

body {font-family: Arial;}
p {font-family: Quill, Arial;}

Thinking more about this, one way to fix this would be to allow the following:

p {font-family: Quill, inherit}
p {font-family: Quill, default}

The second rule is essentially what browsers do at the moment, but only implicitly. If CSS allowed us to specify the last property explicitly, we could alter this behaviour. Unfortunately, this does not work currently. Anybody know how to submit suggestions to the w3C?

Rupert
+1 for testing.
BoltClock