Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is font-family not properly cascading in this button?

Tags:

css

fonts

Here is the link:

http://jsfiddle.net/LDEt6/

The first CSS rule sets the font-family as 'Helvetica Neue', Helvetica, Arial, sans-serif; and all other font settings in the CSS below simply state 'inherit'.. in Chrome 21 however I am getting "Times" as the computed font-family and in Firefox I am getting 'serif'. What am I missing?

Thanks!

like image 861
stupidkid Avatar asked Sep 20 '12 23:09

stupidkid


People also ask

What determines which font family a font comes in?

When a font is only available in some styles, variants, or sizes, those properties may also influence which font family is chosen. The font-family property lists one or more font families, separated by commas.

Where does the font family of the button element come from?

If you inspect your demo in a browser using its Developer Tools, you can see that the font family of the button element comes from the browser style sheet.

Is font-family inherited automatically in case of <button> tags?

I have noticed that in case of <button> tags, font-family is not inherited automatically; either I must specify it explicitly like: However, the font-family is automatically inherited in case of other tags, the <a> tag for example. Why do we have this issue with the <button> tags?

What is @font-family in CSS?

font-family. The font-family CSS property specifies a prioritized list of one or more font family names and/or generic family names for the selected element. Values are separated by commas to indicate that they are alternatives.


1 Answers

First we have:

body {
     font-family : 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

Cool, thats fine. But then we have:

html, body, input, button, <snipped...> {
     font: inherit;
}

So font get overwritten by this rule which also applies to body, it is now inherit.

So what does inherit do? It says "use the styling property assigned to my parent element". In this case, the parent of <body> element is <html> which has no parent. So no specified font family at all at the root, so nothing can inherit.

What inherit does not do, is use the previously defined value for that element. It inherits from the parents, not the previous style that would have applied. inherit is about HTML structure, not CSS structure.

In the end, you set the entire universe to inherit a font from its parent, including all parents. So you never actually find a parent with a real set font. Instead the browser applies its default font, just so it can render something.

If you move your body font rule after to giant reset rule there, it should start working. Fonts will then inherit all the way up to the body tag, which has a real font now.

like image 174
Alex Wayne Avatar answered Oct 09 '22 11:10

Alex Wayne