此 font: 速记属性语法有效吗? (我对规范的阅读表明是的,但我安装的浏览器中有一半不同意。)

发布于 2024-10-29 09:28:46 字数 694 浏览 2 评论 0原文

这是有效的吗? 字体:粗体10px/13px继承;

根据我对规范应该意味着“粗体”的字体粗细、“继承”的字体系列、“10px”的字体大小和“13px”的行高。

它似乎在 Internet Explorer 8 (8.0.6001.18702) 中正常工作。

它在 Windows 上的 Safari 5.0.4 (7533.20.27) 中正常工作。

Opera 11.01(build 1190)和 Firefox 3.6.16 都记录了有关它的错误。

我还没有尝试过 Chrome 或 Firefox 4。

如果这确实应该被验证,那么这个解析错误是否是一个已知问题?

还有几点:

  • W3 验证器也将其报告为无效。
  • 没有“字体:粗体 10px 继承;”、“字体:粗体 10px/13px;”或“字体:粗体 10px;”在 Firefox 中也可以正常工作。

更新

正如 Adam Wagner 在他的回答中指出的那样,由于 CSS2.1 规范的第 C.3.1 节,我尝试的值实际上是无效的(尽管我对规范的天真阅读表明了这一点)。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

痕至 2024-11-05 09:28:46

我认为问题在于“继承”你的价值。

根据规格:

[ [ <'font-style'>; || <'字体变体'> || <'字体粗细'> ]? <'字体大小'> [ / <'行高'> ]? <'字体系列'> ]
|标题
|图标
|菜单
|消息框
|继承

我认为上面列出的粗体部分是一个选项,“标题”、“图标”、“菜单”、“消息框”和“继承”是其余选项。

简而言之,请尝试: font:bold 10px/13px

更新:

看来 webkit 对于这个问题有一个突出的错误报告。不确定火狐浏览器。 (https://bugs.webkit.org/show_bug.cgi?id=20181)

此外,正如票证中的某人提到的,2.1 规范解决了这个问题:

“简写属性采用子属性值列表或值‘继承’。不能将‘继承’与其他子属性值混合,因为不可能指定应用“继承”的子属性 许多速记属性的定义不强制执行此规则:“border-top”、“border-right”、“border-bottom”、“border-left”、“border”。 '、'背景'、'字体'、'列表样式'、'提示'和'轮廓'。”

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

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

撩人痒 2024-11-05 09:28:46

根据标准,您不能使用继承以及 font 复合样式中的其他选项。

必须指定 font-size 和 font-family 值(如果您不使用任何根本不使用它们的表单)。

所以,你不能用它只设置粗细、大小、行高,而是继承家族。

According to the standards, you can't use inherit along with other options in the font composite style.

Both the font-size and font-family values have to be specified (if you don't use any of the forms where they are not used at all).

So, you can't use it to only set the weight, size, line-height, but inheriting the family.

翻身的咸鱼 2024-11-05 09:28:46

很明显,关键字inherit 会带来麻烦。 也许是因为CSS试图让它工作,即使你没有遵循规定的选项顺序(似乎并非如此,因为不同的顺序也不起作用)并且它无法决定什么指令确实继承属于。

如果您显式设置字体系列,则效果很好:font:bold 10px/13px serif;

It's obvious that the keyword inherit causes trouble. Maybe because CSS is trying to make it work even if you didn't follow the prescribed order of options (seems not to be the case because different order doesn't work either) and it cannot decide to what directive does inherit belong to.

It works fine if you explicitly set the font family: font: bold 10px/13px serif;

ま昔日黯然 2024-11-05 09:28:46

我的解决方案如下(在为您的网站使用大型复合字体系列声明时创建尽可能少的 CSS 开销):

.my-class {
  font: bold 1.167em/2 Helvetica;
  font-family: inherit;
}
  • 在 FF 中进行测试(并工作),我遇到了上述问题。

My solution follows (to create as little CSS overhead as possible when using a large composite font-family declaration for your site):

.my-class {
  font: bold 1.167em/2 Helvetica;
  font-family: inherit;
}
  • Tested (and working) in FF where I was having the above issue.
幻梦 2024-11-05 09:28:46

不。

字体简写属性是

font: 12px normal Arial;

字体简写是大小、粗细、字体样式。字体中的行高是 css 中的一个非常非常新的功能,我还不建议使用它。只需添加

line-height: 13px;

单独包含行高并没有真正的额外努力,直到它是跨浏览器,包括速记字体的行高,我根本不会使用它。

No.

the font shorthand property is

font: 12px normal Arial;

Font shorthand is size, weight, font-style. Line height in font is a very very new addition in css and I wouldn't recommend using it just yet. Just add

line-height: 13px;

It is no real extra effort in including the line-height seperately, and until it is cross browser including the line-height in shorthand hand font I would not use it at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文