Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this font: shorthand property syntax valid? (My reading of the spec says yes, but half of my installed browsers disagree.)

Tags:

css

fonts

Is this valid? font: bold 10px/13px inherit;

According to my reading of the specs that should mean a font-weight of 'bold', a font-family of 'inherit', a font-size of '10px', and a line-height of '13px'.

It appears to work correctly in Internet Explorer 8 (8.0.6001.18702).

It works correctly in Safari 5.0.4 (7533.20.27) on Windows.

Opera 11.01 (build 1190) and Firefox 3.6.16 both log errors about it.

I haven't tried Chrome or Firefox 4 yet.

If this is indeed supposed to be valied is this parsing bug a known issue?

A couple extra points:

  • The W3 validator also reports this as being invalid.
  • None of 'font: bold 10px inherit;', 'font: bold 10px/13px;', or 'font: bold 10px;' work correctly in firefox here either.

Update

As pointed out by Adam Wagner in his answer my attempted value is in fact not valid (despite what my naive reading of the spec suggested) due to § C.3.1 of the CSS2.1 spec.

like image 728
Etan Reisner Avatar asked Apr 01 '11 20:04

Etan Reisner


People also ask

Which is the correct order for font shorthand property?

5.5 CSS font shorthand The font property regroups (in this particular order): font-style. font-variant. font-weight.

What is the use of the font shorthand property?

The font CSS shorthand property sets all the different properties of an element's font. Alternatively, it sets an element's font to a system font.

Which of the following properties is used as the shorthand property of font properties?

The font property is used as shorthand for various font properties like font-size, font-style, font-family, font-weight and font-variant. Font properties: font-size: It specifies the size of the text. font-style: It specifies the style of text such as normal, italic, or oblique.

Which property is used as a shorthand method to set all the font properties in one single declaration?

Approach: We will use the font property of CSS which is the shorthand property for all the font properties. This takes five values font-style, font-variant, font-weight, font-size and font-family. The font-size and font-family properties must be set for this property to work.


1 Answers

I think the issue is with the "inherit" addition to your value.

Per the specs:

[ [ <'font-style'> || <'font-variant'> || <'font-weight'> ]? <'font-size'> [ / <'line-height'> ]? <'font-family'> ] | caption | icon | menu | message-box | inherit

I think the bold section I listed above is one option, and "caption", "icon", "menu", "message-box", and "inherit" are the remaining options.

In short, try: font: bold 10px/13px

Update:

It appears webkit has an outstanding bug report on this very problem. Not sure about firefox. (https://bugs.webkit.org/show_bug.cgi?id=20181)

Also, as someone in the ticket mentions, the 2.1 spec addresses this:

"Shorthand properties take a list of subproperty values or the value 'inherit'. One cannot mix 'inherit' with other subproperty values as it would not be possible to specify the subproperty to which 'inherit' applied. The definitions of a number of shorthand properties did not enforce this rule: 'border-top', 'border-right', 'border-bottom', 'border-left', 'border', 'background', 'font', 'list-style', 'cue', and 'outline'."

http://www.w3.org/TR/CSS21/changes.html#q142

like image 186
Adam Wagner Avatar answered Oct 05 '22 20:10

Adam Wagner