查找/设置 css 行高默认值

发布于 2024-12-11 08:15:06 字数 716 浏览 0 评论 0原文

当尝试跨浏览器标准化我的 css 时,我注意到一件奇怪的事情是,h 元素和其他主要标签类型的默认行高属性在 Chrome 和 Firefox 等浏览器中是不同的,但并未在用户代理中设置级别:

这样流行的规范化器也不会处理这个问题。

所以我的问题是两个部分:

  1. 如果没有在用户代理级别设置行高,那么默认值来自哪里?
  2. 我不想自己标准化行高,但如果必须的话,哪里有一些默认值的好例子?

One strange thing I've noticed when trying to normalize my css across browsers is that default line-height properties for h-elements and other major tag types are different across browsers like Chrome and Firefox, and yet are not set at the user-agent level:

Moreover, popular normalizers like normalize.css don't take care of that either.

So my question is two parts:

  1. If line-heights aren't set at the user agent level, where are the default values coming from?
  2. I'd rather not normalize line-heights myself, but if I have to, where is a good example of some defaults?

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

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

发布评论

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

评论(1

音盲 2024-12-18 08:15:06

我同意“事情并不意味着完全相同”在某种程度上是一种逃避,尤其是当 IE 也采用了相当好的标准时。

相对 (120%, 1, 1em) 行高值基于计算的字体大小,正常应该基于字体大小,但它可以并且确实因浏览器而异,正如您通过打开此文件可以看到的FF 和 Chrome 中的示例: http://jsfiddle.net/mahalie/BSMZe/6/

我通常会查看 HTML5 Boilerplate 上的队列最佳实践,因为它是如此受欢迎(因此经过严格审查/经过大量审查。他们使用:

body { margin: 0; font-size: 13px; line-height: 1.231; }

并且他们对它的讨论非常有趣,尽管没有任何观点是明显的赢家:
https://github.com/h5bp/html5-boilerplate/issues/724

I agree that "things aren't meant to be exactly the same" is somewhat of a cop-out, especially as even IE comes on board with pretty good standards adoption.

Relative (120%, 1, 1em) line-height values are based on the computed font-size, Normal is supposed to be based on font size but it can and does vary from browser to browser, as you can see by opening up this example in FF and Chrome: http://jsfiddle.net/mahalie/BSMZe/6/

I generally look to HTML5 Boilerplate for queues on best practices since it is so popular (and therefore well vetted / under a lot of scrutiny. They use:

body { margin: 0; font-size: 13px; line-height: 1.231; }

And their discussion of it is quite interesting although no perspective is the clear winner:
https://github.com/h5bp/html5-boilerplate/issues/724

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