CSS 字体大小:相对值与绝对值.使用哪个? [英] CSS font size: relative vs. absolute values. Which to use?

查看:38
本文介绍了CSS 字体大小:相对值与绝对值.使用哪个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 跨浏览器调整文本大小的最佳方法是什么?
  • 以像素/em 为单位定义字体大小的优缺点是什么?

推荐答案

使用哪个?

两者都有.相对于用户将不得不阅读大量内容的主体文本(因此他们希望能够舒适地阅读);对于必须调整大小以匹配页面上以像素为单位大小的其他元素(例如图像)的文本的绝对值.

Both. Relative for main body text that users are going to have to read a lot of (so they'll want to be able to read it comfortably); Absolute for text that has to be sized to match other elements on the page that are sized in pixels, such as images.

对于相对来说,‘%’和‘em’同样好.

For relative, ‘%’ and ‘em’ are equally good.

对于绝对值,总是使用‘px’.切勿在屏幕上使用pt",它仅适用于打印样式表.遗憾的是,pt"被认为是字体处理的默认单位,因为在网络上它是最糟糕的选择.

For absolute, always use ‘px’. Never use ‘pt’ for on-screen use, it is only sensible for print stylesheets. It is a pity that ‘pt’ is considered the default unit for font-handling because on the web it is the worst possible choice.

(预计到达时间:请注意,从这个答案开始,CSS3 已重新定义物理单位'这样 pxpt 总是成比例的.所以这个问题不再重要,除非你担心非常旧的浏览器.)

(ETA: Note that since this answer, CSS3 has redefined the ‘physical units’ so that px and pt are always proportional. So this problem no longer matters unless you are concerned about very old browsers.)

有些人不喜欢相对字体大小的复合"效果.实际上,诀窍是尽可能少地更改字体大小,以避免过多的嵌套.应该通过使用字体大小关键字small"/medium"/xx-large"/etc,可以在没有复合行为的情况下获得相对于用户的首选大小行为.,但不幸的是,这样你不会得到太多的粒度,而且即使在今天浏览器处理它们的方式之间仍然存在差异.

Some people don't like the ‘compounding’ effect of relative font sizes. The trick, really, is to use as few font-size changes as you can, to avoid too many nestings. It should be possible to get the relative-to-user's-preferred-size behaviour without the compounding behaviour by using the font-size keywords ‘small’/‘medium’/‘xx-large’/etc., but unfortunately that way you don't get much granularity, and there are still even today differences between how the browsers handle them.

这篇关于CSS 字体大小:相对值与绝对值.使用哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆