em单位和百分比之间有什么区别? [英] What's the difference between em units and percents?

查看:161
本文介绍了em单位和百分比之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关该主题的文章(并搜索了问题与解答"),但我仍然不了解em单位和百分比之间的区别.帮助吗?

I have read a lot of articles on this topic (and searched for Q&A), and I have found, but I still don't understand what the difference between em units and percents is. Help?

P.S. 我看过以下代码示例:

P.S. I've seen this code example:

p { font-size: 10px; }
p { line-height: 120%; }  /* 120% of 'font-size' */

那是什么意思?到底为什么有人要将行高设置为字体大小的百分比值?

What is that supposed to mean? Why on earth would anyone want to set a line height to a percentage value of a font size?

推荐答案

好的,所以我决定总结一下答案.

OK, so I've decided to sum up the answers.

  • line-height的百分比值是相对于当前字体大小的.
  • em单位始终与字体大小有关.
  • 百分比取决于上下文.例如,如果以字体大小使用它们,则它们将相对于当前字体大小;如果它处于高度,则它们将相对于高度.
  • 当父标记的字体大小声明为小",中"或大"时,它会有所变化,因为这些值受浏览器设置的影响.在这种情况下,1em = \ = 100%,1em似乎会使设置比100%更小"或更大",请阅读
  • line-height's percentage value is relative to the current font-size.
  • em units is always relative to font-size.
  • Percents depends on context. For example, if they're used in font-size, they will be relative to the current font-size; if it's in height, they will be relative to the height.
  • It changes a little bit when parent tag has font size declared as "small", "medium" or "large", because values of these are affected by browser's setting. In this context 1em =\= 100%, 1em seems to make setting a bit more "small" or a bit more "large" than 100%, read about it here.

谢谢你们. :)

这篇关于em单位和百分比之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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