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

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

问题描述


  • 在像素/ em中定义字体大小的优点和缺点是什么?


  • 解决方案


    使用哪个?


    < blockquote>

    两者。相对于主体文本,用户将需要阅读很多(所以他们会想要能够舒适地阅读它);



    对于相对值,'%'和'em'是绝对大小的文字,必须与页面上像素大小的其他元素



    对于绝对,总是使用'​​px'。不要在屏幕上使用pt,它只对打印样式表有意义。很遗憾,'pt'被认为是字体处理的默认单位,因为在网络上它是最糟糕的选择。



    (ETA: answer,CSS3已重新定义实体单位,以便

    $ b>


    $ b

    有些人不喜欢相对字体大小的复合效果。诀窍,真的,是使用尽可能少的字体大小的变化,你可以,以避免太多的嵌套。 应该可以通过使用font-size关键字'small'/'medium'/'xx-large'/等来获得相对于用户偏好大小的行为,而无需复合行为。 。但是不幸的是,你没有得到太多的粒度,而且如今的浏览器如何处理它们之间的差异。


    • What's the best way to size text across browsers?
    • What are the advantages and disadvantages of defining font size in pixels / em?

    解决方案

    Which to use?

    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.

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

    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.

    (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.)

    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天全站免登陆