高级前端
css
【Q547】某元素的 fontSize: 2rem; lineHeight: 1.5em; 此时 lineHeight 为多少像素

某元素的 fontSize: 2rem; lineHeight: 1.5em; 此时 lineHeight 为多少像素

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 561 (opens in a new tab)

Author 回答者: HunterXing (opens in a new tab)

font-size: 2rem. ----> 则该元素默认情况下,font-size: 32px line-height: 1.5em, em相对于自身元素的font-size, 则 line-height: 1.5 * 32 === 48px

Author 回答者: liuerhost (opens in a new tab)

rem是相对长度单位,相对于根元素。 em也是相对长度单位,相对于父元素。 浏览器默认 1rem = 16px 所以font-size : 2rem = 2 _ 16px = 32px line-height: 1.5em ,em相对于父元素的font-size (32px) ==> line-height: 1.5em = 1.5 _ 32 = 48px